gpt4 book ai didi

javascript - 构建并部署到 Firebase 后动画停止工作

转载 作者:行者123 更新时间:2023-12-05 02:39:00 25 4
gpt4 key购买 nike

我遇到一个问题,当我npm run-script buildfirebase deploy 我的 React 应用程序到 Firebase 托管时,我的动画停止工作。

不知道为什么会这样,我添加了每个网络浏览器兼容的关键帧。

这是我的应用程序在本地主机上运行时的样子 (npm start):

enter image description here

然后它看起来像是从 firebase 托管的:

enter image description here

就好像它无法读取我的关键帧动画。

这是 index.js:

import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import { Provider } from "react-redux";
import { createStore, applyMiddleware, compose, combineReducers } from "redux";
import thunk from "redux-thunk";
import * as serviceWorker from "./serviceWorker";
import userReducer from "./store/reducers/user";

import { WithClass } from "./hoc/WithClass";
import classes from "./index.module.css";
import App from "./App";

// Icons made by Freepik from www.flaticon.com

// Reducers
const rootReducer = combineReducers({
user: userReducer,
});

// Store
const store = createStore(rootReducer, applyMiddleware(thunk));

const app = (
<Provider store={store}>
<WithClass>
<BrowserRouter>
<App />
</BrowserRouter>
</WithClass>
</Provider>
);

ReactDOM.render(app, document.getElementById("root"));

应用程序.js:

import React from "react";
import { Route, Switch, withRouter, Redirect } from "react-router-dom";

import HomePage from "./pages/HomePage/HomePage";
import AboutPage from "./pages/AboutPage/AboutPage";
import WorkPage from "./pages/WorkPage/WorkPage";
import PhotographyPage from "./pages/PhotographyPage/PhotographyPage";
import ContactPage from "./pages/ContactPage/ContactPage";
import { WithClass } from "./hoc/WithClass";

/**
* Contains switch routing to components
*
* Called by index.js in ReactDOM.render()
*/
const App = () => {
return (
<WithClass>
<Switch>
<Route path="/about" exact component={AboutPage} />
<Route path="/work" exact component={WorkPage} />
<Route path="/photography" exact component={PhotographyPage} />
<Route path="/contact" exact component={ContactPage} />
<Route path="/" exact component={HomePage} />
<Redirect to="/" />
{/* Redirect anything other than routes specified to "/" */}
</Switch>
</WithClass>
);
};

export default withRouter(App);

主页.js:

import React, { useEffect } from "react";
import AnimatedSlideShowText from "../../components/UI/AnimatedSlideShowText/AnimatedSlideShowText";
import HeaderAnimated from "../../components/UI/HeaderAnimated/HeaderAnimated";
import HeaderStatic from "../../components/UI/HeaderStatic/HeaderStatic";
import SocialMediaFooter from "../../components/UI/SocialMediaFooter/SocialMediaFooter";
import { useDispatch, useSelector } from "react-redux";
import { loadedOnce } from "../../store/actions/user";

import classes from "./HomePage.module.css";

const HomePage = () => {
const dispatch = useDispatch();
const didLoadOnce = useSelector((state) => state.user.loadedOnce);

useEffect(() => {
setTimeout(() => {
dispatch(loadedOnce());
}, 2000);
}, []);

return (
<div className={classes.MainContainer}>
<div className={classes.HeaderContainer}>
{didLoadOnce ? <HeaderStatic /> : <HeaderAnimated />}
</div>
<div className={classes.BodyContainer}>
<div className={classes.NameContainer}>
<AnimatedSlideShowText tag="h1">
Christian Nicoletti
</AnimatedSlideShowText>
<AnimatedSlideShowText
tag="h2"
mainTextStyle={classes.Title}
>
Software Engineer
</AnimatedSlideShowText>
<AnimatedSlideShowText
tag="h3"
mainTextStyle={classes.School}
>
University of California, Santa Cruz graduate
</AnimatedSlideShowText>
</div>
<div className={classes.FooterContainer}>
<SocialMediaFooter />
</div>
</div>
</div>
);
};

export default HomePage;

主页.module.css:

.MainContainer {
width: 100vw;
height: 100vh;
min-width: 1500px;
}

.BodyContainer {
display: flex;
height: 100%;
justify-content: center;
margin-left: 20%;
flex-direction: column;
}

.NameContainer {
display: flex;
height: 250px;
width: 500px;
}

.Title {
margin-top: 60px;
-webkit-animation-delay: 0.2s;
animation-delay: 0.2s;
}

.School {
margin-top: 120px;
-webkit-animation-delay: 0.3s;
animation-delay: 0.3s;
}

.HeaderContainer {
position: absolute;
right: 100px;
}

.FooterContainer {
width: 500px;
}

AnimatedSlideShowText.js:

import React from "react";
import classes from "./AnimatedSlideShowText.module.css";

const AnimatedSlideShowText = (props) => {
const CustomTag = `${props.tag}`;
return (
<CustomTag className={`${classes.MainText} ${props.mainTextStyle}`}>
{props.children}
</CustomTag>
);
};

export default AnimatedSlideShowText;

AnimatedSlideShowText.module.css:

.MainText {
color: white;
position: absolute;
opacity: 0;
margin-left: -10%;
font-family: Calibri;
font-weight: 300;
-webkit-animation: slide 0.5s forwards;
animation: slide 0.5s forwards;
}

@-o-keyframes slide {
100% {
margin-left: 0%;
opacity: 100%;
}
}

@-ms-keyframes slide {
100% {
margin-left: 0%;
opacity: 100%;
}
}

@-moz-keyframes slide {
100% {
margin-left: 0%;
opacity: 100%;
}
}

@-webkit-keyframes slide {
100% {
margin-left: 0%;
opacity: 100%;
}
}

@keyframes slide {
100% {
margin-left: 0%;
opacity: 100%;
}
}

@-webkit-keyframes show {
/* Chrome, Safari */
0% {
width: 100%;
}
100% {
width: 0%;
}
}
@-moz-keyframes show {
/* FF */
0% {
width: 100%;
}
100% {
width: 0%;
}
}
@-ms-keyframes show {
/* IE10 */
0% {
width: 100%;
}
100% {
width: 0%;
}
}
@-o-keyframes show {
/* Opera */
0% {
width: 100%;
}
100% {
width: 0%;
}
}
@keyframes show {
0% {
width: 100%;
}
100% {
width: 0%;
}
}

我会添加更多组件源代码,但我认为 AnimatedSlideShowText 是理解问题所需的全部内容。

再说一次,我只是想让我的动画在构建和部署时正常工作。我不确定为什么它们会在构建和部署时停止工作。

在构建/部署时使用 module.css 是否可能对动画产生影响?非常感谢任何帮助,如果您需要更多源代码,请告诉我。

最佳答案

我以前遇到过类似的问题,但我使用的是 CSS 框架。问题出在我的托管服务提供商的构建缓存上。当使用 create-react-app(使用 Webpack)时,在构建阶段会发生所谓的“摇树”。它从您的模块中删除未使用的样式、类等。

在本地工作的模块可能无法在生产中工作,因为它在您的第一个构建中被删除,然后由于构建缓存而没有在新构建中使用。

我不知道它是否能解决您的问题,但我建议您检查一下,因为它过去对我有用。

关于javascript - 构建并部署到 Firebase 后动画停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69291562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com