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

Categories

0 votes
743 views
in Technique[技术] by (71.8m points)

javascript - Turn off firefox's smooth scrolling?

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

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

1 Answer

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...