Here is a working example of horizontal scroll with mousewheel, but it does not scroll smoothly. By smoothly I mean like ordinary vertical scroll in Firefox or Opera.
$(function() {
$("html, body").mousewheel(function(event, delta) {
this.scrollLeft -= (delta * 30);
event.preventDefault();
});
});
(http://brandonaaron.net/code/mousewheel/docs)
I've made a live demo to demonstrate this. http://jsfiddle.net/Dw4Aj/
I want this scroll to work like the vertical one, both with mousewheel and smoothness.
Can someone help me?
You can use window. scroll() with behavior: smooth and top set to the anchor tag's offset top which ensures that the anchor tag will be at the top of the viewport.
Scroll horizontally using a keyboard and mousePress and hold SHIFT. Scroll up or down using your mouse wheel (or another vertical scrolling function of your mouse).
In the Flags tab, search for the Smooth Scrolling setting. You can do this manually in the Available tab or use the search bar to find it. Once you've located it, press the drop-down menu next to the feature and select Enabled or Disabled.
Smooth scrolling is a browser specific feature.
If you want something that works on all of them then you need to do it on your side. There are multiple implementations of smooth scrolling for jQuery.
And actually you may even need so called kinetic scrolling. If so try jquery.kinetic
1st i think about it is to remember last scroll event timestamp, play with easing function, to get good result http://jsfiddle.net/oceog/Dw4Aj/13/
$(function() {
$("html, body").mousewheel(function(event, delta) {
var mult = 1;
var $this = $(this);
if (event.timeStamp - $this.data('oldtimeStamp') < 1000) {
//calculate easing here
mult = 1000 / (event.timeStamp - $this.data('oldtimeStamp'));
}
$this.data('oldtimeStamp', event.timeStamp);
this.scrollLeft -= (delta) * mult;
event.preventDefault();
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With