首页 > 解决方案 > 如果单击调查下一个按钮,我如何禁用滚动

问题描述

知道为什么每次单击其中一个答案时,整个屏幕都会突然移动到顶部吗?

调查链接:https ://app.grillomarketing.com/v2/preview/Gg3ERkkv4fCAUmGor5pL

标签: scroll

解决方案


function disableScroll() {
    scrollTop = window.pageYOffset || document.documentElement.scrollTop;
    scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
  
        // if any scroll is attempted, set this to the previous value
        window.onscroll = function() {
            window.scrollTo(scrollLeft, scrollTop);
        };
}
  
function enableScroll() {
    window.onscroll = function() {};
}

This code will disable scroll fully but you might have some event listener that scrolls to the element when button is clicked.

code source


推荐阅读