How to make mouse wheel scroll smooth in Windows OS

Article

Hey dude! You’ve developed a lovely parralax website but it looks jerky with mouse wheel on Microsoft Windows OS browsers? Don’t worry, with this following code, you’ll make the scrolling smooth as in Mac OS:

1 jQuery code

$html = ($.browser.safari) ? $("body, html, document") : $("html, body”);
// How many pixels to scroll
var scrollHeight = 250;
if ($.client.os == "Windows") {
    $('body').mousewheel(function(event, delta) {
        // disable native scroll
        if(event.preventDefault) {
            event.preventDefault();
        } else { // IE fix
            event.returnValue = false;
        };
        $html.stop().animate({
            scrollTop: $html.scrollTop() + (-delta * scrollHeight)
        }, 'slow');
    });
}
Notes

  1. 1 Detect the Operating System with the Stoimen plugin
  2. 2 To bind an event on mouse wheel, we need to include the jQuery Mousewheel Plugin developed by Brandon Aaron.

2 Demo

If you are in Windows OS, you can use the mouse wheel to see the demo.

If you like (or not) this article, you can write a comment 7 or a tweet 5.

Discussion 7 comments - RSS feed

  1. Manuel

    Dear Franck,

    I love your code but i’m having issues making the page scroll to the bottom in Safari & chrome.

    I’ve tested it in the following browsers:
    - IE 9.0 (ok)
    - FF 7.01 (ok)
    - Opera 11.52 (ok)
    - Safari 5.1.1 (not ok)
    - Chrome 15 (not ok)

    Could you give some advice on how to fix this?

    Greetings,
    Manuel

  2. Aldo

    I found the solutions for chrome/safari based browsers:

    just add this line:

    if($.browser.safari) $html = $(“body,hmtl,document”)
    else $html = $(“html,body”)

    intead of

    var $html = $(‘html,body’);

  3. Andres Riofrio

    This breaks on Firefox 13-14, with (Firefox’s) smooth scrolling activated. With this script in the page, each mouse wheel click scrolls double of what it does on other pages.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>