每当我将translate()
CSS 函数添加到元素将离开视口的react-spring
useTransition
钩子from
或leave
属性时,我都会得到一个垂直/水平滚动条。
const transitions = useTransition(show, null, {
from: {
opacity: 0,
transform: "translate3d(500px,0px,0px) scale(1)"
},
enter: {
opacity: 1,
transform: "translate3d(0px,0px,0px) scale(1)"
},
leave: {
opacity: 0,
transform: "translate3d(0px,-500px,0px) scale(1)"
},
config: {
duration: 3000
}
});
我知道这是意料之中的,一般的解决方案是添加overflow: hidden
到body
.
但是我不确定在动画发生时如何执行此操作?因为我不想一直添加overflow: hidden
,body
因为我确实需要访问某些页面中的滚动条,而不是在动画启动时?
这是一个CodeSandbox供您自己尝试
任何帮助将不胜感激。