当前的界面:
我想要的是,当滚动到红色部分时,百分比就开始增加
在百分比增加到100%之前,用户无法继续向下滚动。
示例: https://circleci.com/#advantage-flexibility
如何实现?
App.js
import "./styles.css";
import { useScrollPercentage } from "react-scroll-percentage";
export default function App() {
const [ref, percentage] = useScrollPercentage({
/* Optional options */
threshold: 0
});
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>{" "}
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<div ref={ref} style={{ color: "red" }}>
<h1>
When the scroll arrive this div, the position of this div will become
sticky, and the percentage will start to increase from 0 to 100. When
arriving 100%, user can then scroll to next section
</h1>
<h2>{`Percentage scrolled: ${percentage.toPrecision(2)}%.`}</h2>
</div>
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
<h1>Hello CodeSandbox</h1>
<h2>Start editing to see some magic happen!</h2>
</div>
);
}
Codesnadbox:
https://codesandbox.io/s/divine-bird-9fy50?file=/src/App.js:0-1365