【发布时间】:2022-01-05 07:05:36
【问题描述】:
当前用户界面:
当我想做的是,当滚动到达红色部分时,百分比会开始增加
在百分比增加到 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
【问题讨论】:
-
嘿@CCCC,请告诉我哪种解决方案可以奖励他们。
标签: javascript html css reactjs