你可以用这样的东西WITH HOOKS:
import React, { useRef, useEffect } from "react";
import Rellax from "rellax";
export default function App() {
const rellaxRef = useRef();
useEffect(() => {
new Rellax(".animate", { // <---- Via class name
speed: -10,
center: false,
wrapper: null,
round: true,
vertical: true,
horizontal: false
});
new Rellax(rellaxRef.current, { // <---- Via useRef element
speed: -10,
center: false,
wrapper: null,
round: true,
vertical: true,
horizontal: false
});
}, []);
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<div ref={rellaxRef}>
Lorem Ipsum is simply dummy text of the printing and typesetting
</div>
<div className="animate">I’m that default chill speed of "-2"</div>
</div>
);
}
WORKING DEMO(您可以滚动查看)