fix: later scroll button
This commit is contained in:
parent
85d10bfa40
commit
6ced902d93
|
|
@ -6,8 +6,8 @@ const ScrollUpButton = () => {
|
||||||
const [state, setState] = React.useState({display: 'none', opacity: 0});
|
const [state, setState] = React.useState({display: 'none', opacity: 0});
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const scrollHandler = () => {
|
const scrollHandler = () => {
|
||||||
const currentScrollPos = window.pageYOffset;
|
const currentScrollPos = Math.max(window.pageYOffset - 1000, 0);
|
||||||
const opacity = Math.min(currentScrollPos / 500, 1);
|
const opacity = Math.min(currentScrollPos / 1000, 1);
|
||||||
const nextState = {display: currentScrollPos > 0 ? 'inherit' : 'none', opacity};
|
const nextState = {display: currentScrollPos > 0 ? 'inherit' : 'none', opacity};
|
||||||
if (state.display !== nextState.display || state.opacity !== nextState.opacity) {
|
if (state.display !== nextState.display || state.opacity !== nextState.opacity) {
|
||||||
setState(nextState);
|
setState(nextState);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue