qwertymk
qwertymk

Reputation: 35276

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

Upvotes: 2

Views: 2384

Answers (2)

superluminary
superluminary

Reputation: 49162

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

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. You'll then need to do some maths to determine if the current scroll position has changed enough to trigger the next animation.

Upvotes: 0

Esailija
Esailija

Reputation: 140220

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/

Upvotes: 3

Related Questions