如何以编程方式禁用IE 11中的平滑滚动 [英] How to disable Smooth Scrolling in IE 11 programatically

查看:71
本文介绍了如何以编程方式禁用IE 11中的平滑滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于滚动事件进行ajax调用,该调用在除IE11之外的所有浏览器中均能正常运行,并且我发现了为什么通过默认启用IE11启用了平滑滚动"功能,所以ajax调用经常被调用,因此如何使用javascript或jquery禁用该设置,所有回复都将获得完整的帮助.

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.

提前谢谢.

推荐答案

OS X,iOS Safari 8+和更高版本上的所有浏览器都具有相同的行为.您不能也绝对不应更改它.

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.

打开浏览器的控制台,然后查看此示例.您会看到经常调用滚动",但限制滚动"最多每200ms调用一次.

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>

>

这篇关于如何以编程方式禁用IE 11中的平滑滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆