First off, the codepen *works*, HOWEVER, when I use VSCode live server and test the following code (which is exactly the same as the codepen), I'm running into the problem on Android, iPhone and iPad.
As I scroll down to the bottom of the page, and stop scrolling for a second, the page randomly scrolls itself up or down (usually up) a bit. I can't seem to recreate the problem on my laptop or with devtools, so maybe it has something to do with touch devices? The weirdest thing is that I'm only having the problem when using VSCode live server (and, originally, on Webflow where the full site is being built), but I'm not having the problem with the same exact code on codepen. Maybe because codepen is using an iFrame?
Any ideas? Here is minimal amount of code required to recreate the issue with VSCode live server:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<style>
html {
scroll-behavior: smooth;
}
.spacer {
height: 100vh;
background: #f0f0f0;
}
</style>
</head>
<body class="body">
<div class="spacer"></div>
<div class="container">
<div class="anim__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tincidunt tristique arcu ut eleifend. Vestibulum ultricies sit amet tellus ac faucibus. Ut dui dui, viverra eget condimentum non, fringilla non magna.</div>
</div>
<div class="spacer"></div>
<div class="container">
<div class="anim__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tincidunt tristique arcu ut eleifend. Vestibulum ultricies sit amet tellus ac faucibus. Ut dui dui, viverra eget condimentum non, fringilla non magna.</div>
</div>
<div class="spacer"></div>
<div class="container">
<div class="anim__text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris tincidunt tristique arcu ut eleifend. Vestibulum ultricies sit amet tellus ac faucibus. Ut dui dui, viverra eget condimentum non, fringilla non magna.</div>
</div>
<div class="spacer"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/gsap.min.js" integrity="sha512-VEBjfxWUOyzl0bAwh4gdLEaQyDYPvLrZql3pw1ifgb6fhEvZl9iDDehwHZ+dsMzA0Jfww8Xt7COSZuJ/slxc4Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.10.4/ScrollTrigger.min.js" integrity="sha512-v8B8T8l8JiiJRGomPd2k+bPS98RWBLGChFMJbK1hmHiDHYq0EjdQl20LyWeIs+MGRLTWBycJGEGAjKkEtd7w5Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
const initRevealTextOnScroll = () => {
gsap.utils.toArray(".anim__text").forEach((text, i) => {
gsap.to(text.parentElement, {
scrollTrigger: {
trigger: text.parentElement,
pin: true,
start: "center center",
end: "+=1000",
}
});
});
}
const initAnimations = () => {
gsap.registerPlugin(ScrollTrigger);
initRevealTextOnScroll();
}
window.addEventListener('load', e => {
console.log('Window fully loaded');
initAnimations();
});
</script>
</body>
</html>
Edit: I made a short YouTube video to show what's happening for me: