简体   繁体   English

关闭firefox的平滑滚动?

[英]Turn off firefox's smooth scrolling?

Firefox's new smooth scrolling feature causes the scroll callback to trigger at each step in the animation. Firefox的新平滑滚动功能会导致滚动回调在动画的每一步触发。

DEMO in FF and Chrome to see the difference FF和Chrome中的DEMO看到了差异

Is there any way to have it so that it 有没有办法让它如此

  1. Only fires one event when the page has finished scrolling 仅在页面完成滚动时触发一个事件
  2. Make the page scroll abruptly like it does in Chrome 使页面突然像在Chrome中一样滚动

Try this: 尝试这个:

function throttle( fn, timeout ) {
    var tid = 0;
    return function() {
        clearTimeout( tid );
        var args = [].slice.call( arguments ),
            ctx = this;

        tid = setTimeout( function() {
            fn.apply( ctx, args );
        }, timeout );
    };
}

$(window).on("scroll", throttle( function() {
    $('div').eq(0).append('scroll happened');
}, 100));

It will only fire the scroll once no scroll has happened in 100 milliseconds. 一旦在100毫秒内没有发生滚动,它将仅触发滚动。

http://jsfiddle.net/NLGHS/1/ http://jsfiddle.net/NLGHS/1/

It depends on your purpose. 这取决于你的目的。 I'm taking a guess based on your code that you would like to trigger an animation as the user scrolls down the page, a bit like Ben the Bodyguard: http://benthebodyguard.com/index.php 我根据您的代码猜测,当用户向下滚动页面时,您想要触发动画,有点像Ben the Bodyguard: http//benthebodyguard.com/index.php

To achieve this, you tie the animation to the position in the page. 为此,您可以将动画绑定到页面中的位置。 You can get the current scroll position from the event object that is passed to the scroll method. 您可以从传递给scroll方法的事件对象获取当前滚动位置。 You'll then need to do some maths to determine if the current scroll position has changed enough to trigger the next animation. 然后,您需要做一些数学运算来确定当前滚动位置是否已经改变到足以触发下一个动画。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM