Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Firefox's new smooth scrolling feature causes the scroll callback to trigger at each step in the animation.

DEMO in FF and Chrome to see the difference

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
728 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...