Hey folks,
So i’m having an issue with a prototype i’m working on. I’ve added a smooth inertia scroll using GSAP. But i figured out when you open the last tab (try to open the latest tab on the page), the scroll container doesn’t recalculate, so you can’t scroll at the bottom of the page…
Any help would be much appreciated if any of you had the same issue or a workaround!
You can see the prototype here : http://dlj-prototype.webflow.io/
Here is the custom css added :
*, :after, :before {
box-sizing: border-box;
}
body {
overflow-x: hidden;
overflow-y: scroll;
}
.scroll-container {
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
And here is the custom javascript :
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/2.0.2/TweenMax.min.js" type="text/javascript"></script>
<script>
var html = document.documentElement;
var body = document.body;
var scroller = {
target: document.querySelector("#scroll-container"),
ease: 0.05, // <= scroll speed
endY: 0,
y: 0,
resizeRequest: 1,
scrollRequest: 0,
};
var requestId = null;
TweenLite.set(scroller.target, {
rotation: 0.01,
force3D: true
});
window.addEventListener("load", onLoad);
function onLoad() {
updateScroller();
window.focus();
window.addEventListener("resize", onResize);
document.addEventListener("scroll", onScroll);
}
function updateScroller() {
var resized = scroller.resizeRequest > 0;
if (resized) {
var height = scroller.target.clientHeight;
body.style.height = height + "px";
scroller.resizeRequest = 0;
}
var scrollY = window.pageYOffset || html.scrollTop || body.scrollTop || 0;
scroller.endY = scrollY;
scroller.y += (scrollY - scroller.y) * scroller.ease;
if (Math.abs(scrollY - scroller.y) < 0.05 || resized) {
scroller.y = scrollY;
scroller.scrollRequest = 0;
}
TweenLite.set(scroller.target, {
y: -scroller.y
});
requestId = scroller.scrollRequest > 0 ? requestAnimationFrame(updateScroller) : null;
}
function onScroll() {
scroller.scrollRequest++;
if (!requestId) {
requestId = requestAnimationFrame(updateScroller);
}
}
function onResize() {
scroller.resizeRequest++;
if (!requestId) {
requestId = requestAnimationFrame(updateScroller);
}
}
const tabBtn = document.querySelectorAll('.dpdp');
for (var i = 0; i < tabBtn.length; i++) {
tabBtn[i].addEventListener('click', function(event) {
scroller.resizeRequest++;
});
}
</script>
Here is my site Read-Only: LINK
(how to share your site Read-Only link)