How to make mouse wheel scroll smooth in Windows OS
Article- Posted at
- 7 comments for this post
- Permalink
- jQuery parallax
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');
});
}
- 1 Detect the Operating System with the Stoimen plugin
- 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.
Great script!
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
ps: i love the rss subscibe to comments, never seen that before. Nice feature!
Hello Franck, thanks, that’s what I was looking for.
Looks fine except on webkit browser.
Wondering if it can be applied to jScrollPane too.
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’);
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.
Great stuff – with Aldo’s fix it works perfect for me
Thanks guys