How to disable Smooth Scrolling in IE 11 programatically

六月ゝ 毕业季﹏ 提交于 2021-01-29 06:35:22

问题


I am making ajax call based on scroll event that calls are working perfectly in all browsers except IE11 and I found the reason why because by deafault "Smooth Scrolling" is enabled for IE11 SO the ajax calls are calling frequently, so how to disable that setting using javascript or jquery, any reply is help full.

Thanks in advance.


回答1:


All browsers on OS X, iOS Safari 8+, and a lot more have the same behavior. You can't and definitely shouldn't change it.

What you can do is limit the rate at which your function is called. Throttle it.

Open the your browser's console and look at this example. You'll see that the "scroll" is called often but the "throttled scroll" only once every 200ms at most.

var handler = function () {
	console.log('scroll');
};
var throttledHandler = throttle(function () {
	console.log('throttled scroll');
}, 200);

window.addEventListener('scroll', handler);
window.addEventListener('scroll', throttledHandler);

function throttle (callback, limit) {
    // source: http://sampsonblog.com/749/simple-throttle-function
    var wait = false;                 // Initially, we're not waiting
    return function () {              // We return a throttled function
        if (!wait) {                  // If we're not waiting
            callback.call();          // Execute users function
            wait = true;              // Prevent future invocations
            setTimeout(function () {  // After a period of time
                wait = false;         // And allow future invocations
            }, limit);
        }
    }
}
<p>scroll me</p>
<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p><p>1</p><p>1</p><p>1</p><p>1</p><p>1</p><p>---</p>


来源:https://stackoverflow.com/questions/31264290/how-to-disable-smooth-scrolling-in-ie-11-programatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!