Hello,
I’m new to Webflow and currently building my first site, which is a one-pager. In the navigation header, I’d like to have some links guiding the visitor to specific sections of my page. I’m having the issue that jumping works fine, but the scroll bar seems to be frozen. It means that when you jump to a section that way and try to scroll from there, you’re back at the page position where you initially clicked the jump link. I tried both the built-in jump fuctionality as well as custom code, ending up with the exact same result. Here’s one of the numerous versions of code I’ve tried:
<script>
window.addEventListener("load", function () {
const scrollBtn = document.querySelector('.btn-upwards');
if (!scrollBtn) {
console.warn("Button .btn-upwards nicht gefunden");
return;
}
scrollBtn.addEventListener('click', function (e) {
e.preventDefault();
if ('scrollRestoration' in history) {
history.scrollRestoration = 'manual';
}
// Alle scrollTop-Werte zurücksetzen
document.querySelectorAll('*').forEach(el => {
el.scrollTop = 0;
});
// Und für window zur Sicherheit
window.scrollTo({ top: 0, behavior: 'smooth' });
// Nach kurzer Zeit nochmal hard reset
setTimeout(() => {
document.querySelectorAll('*').forEach(el => {
el.scrollTop = 0;
});
window.scrollTo(0, 0);
}, 500);
});
});
</script>
Can somebody pls explain to me why this is happening and how to fix it?