admin管理员组文章数量:1355660
Here is my App.js Code
import React from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import AOS from "aos";
import "aos/dist/aos.css";
import Home from "../Home/Home";
AOS.init();
function App() {
return (
<>
<div className="App">
<Router>
<Route path="/">
<Home />
</Route>
</Router>
</div>
</>
);
}
export default App;
export default App;
Home.jsx
import React from "react";
export default function Home() {
return (
<>
<div className="mitments">
<p data-aos="fade-left">This is text fading</p>
</div>
</>
);
}
I think this is the correct way, before using data-aos="fade-left" it working fine, But when I use data-aos the text got disappeared. I'm not getting what is the issue.
Here is my App.js Code
import React from "react";
import { BrowserRouter as Router, Route } from "react-router-dom";
import AOS from "aos";
import "aos/dist/aos.css";
import Home from "../Home/Home";
AOS.init();
function App() {
return (
<>
<div className="App">
<Router>
<Route path="/">
<Home />
</Route>
</Router>
</div>
</>
);
}
export default App;
export default App;
Home.jsx
import React from "react";
export default function Home() {
return (
<>
<div className="mitments">
<p data-aos="fade-left">This is text fading</p>
</div>
</>
);
}
I think this is the correct way, before using data-aos="fade-left" it working fine, But when I use data-aos the text got disappeared. I'm not getting what is the issue.
Share Improve this question asked May 2, 2021 at 17:36 Nimra HaiderNimra Haider 2394 silver badges12 bronze badges2 Answers
Reset to default 7You should run AOS.init();
after your app mounts:
function App() {
useEffect(() => {
AOS.init();
}, []);
return (
<>
<div className="App">
<Router>
<Route path="/">
<Home />
</Route>
</Router>
</div>
</>
);
}
Since this library isn't designed for React, you will probably have to re-initialize this in future when your ponent re-renders. I remend using an animation library built for React.
// Initialize AOS with custom settings
setTimeout(() => {
AOS.init({
duration: 1000, // Duration of animations in ms
disable: function() {
// Disable for mobile devices (screen width less than 768px)
return window.innerWidth < 768;
}
});
}, 1000);
}, []); //setTimeout will resolve issue
本文标签: javascriptAOS(Animation on scroll) is not working in React jsStack Overflow
版权声明:本文标题:javascript - AOS(Animation on scroll) is not working in React js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744052974a2582760.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论