How to scroll horizontal in na div with mouse whell, or drag with jquery?
I've tried draggable, byt in my code it's not usefull.
Now I've got a horizontal scrollbar. Is there a posibility to scroll the content in my div with mouse wheel?
How to scroll horizontal in na div with mouse whell, or drag with jquery?
I've tried draggable, byt in my code it's not usefull.
Now I've got a horizontal scrollbar. Is there a posibility to scroll the content in my div with mouse wheel?
Try this for horizontal scrolling with mouse wheel. This is pure JavaScript:
Here's a demo, but with
document.body
andwindow
as a targetted element: http://rawgit.com/tovic/dte-project/master/full-page-horizontal-scrolling.htmlIn my case I needed to reset the scroll back to normal when the browser was resized, so I modified Izhar's code a bit to make it work for my application:
Initiate hScroll on browser resize:
Check if container has white-space property set to 'nowrap' and return if not:
};
I use this media query to update the white-space property:
Hope this helps anyone wanting to do the same.
I'd like to add a slight improvement to the answer given by @Taufik.
In the context of an
es2015
module:The main difference being:
el.scrollLeft -= (e.wheelDelta || -e.detail);
Using the
e.wheelData
directly in the scroll offset means we can have the inertia, so that the scrolling can slow down gradually. I found this worked well for me.Just use in your code like so (assuming the above code is in a file called scroller.js):
Wrote this plugin days ago.
Try it out with
The width of the child element of the div should be wider than the parent.
Like 4000 px or something.
I have rewritten the code from the answer by @Anonymous-Lettuce. The width recalculation of the element is skipped as it was unnecessary and sometimes undesirable. This also provides additional feature to pass
scroll-amount
inpx
to the plugin.Use it like this:
Here goes the upgraded plugin
jquery.hscroll.js
:Here is the minified version of the same
jquery.hscroll.min.js
: