Whenever I add a translate()
CSS function to a react-spring
useTransition
hook from
or leave
property where the element will go out of the viewport, I am getting a vertical/horizontal scrollbar.
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
}
});
I know this is expected and the general solution is to add overflow: hidden
to the body
.
But I am unsure how to do this while the animation is occurring? As I don't want to add overflow: hidden
to the body
at all times as I do need access to the scrollbar in certain pages, just not when the animation has initiated?
Here is a CodeSandbox to try it out for yourselves
Any help would be greatly appreciated.