How to scroll horizontal in na div with mouse wheel, or drag with jquery?
I've tried draggable, but in my code it isn't useful.
Now I've got a horizontal scrollbar. Is there a posibility to scroll the content in my div using the mouse wheel?
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).
Set the overflow-y: hidden; and overflow-x: auto; that will automatically hide the vertical scroll bar and present only the horizontal scrollbar. The white-space: nowrap; property is used to wrap text in a single line. Here the scroll div will be horizontally scrollable.
To enable horizontal scrolling, we can use the CSS property overflow-x. If we assign the value scroll to the overflow-x property of the container element, the browser will hide horizontally overflowing content and make it accessible via horizontal scrolling.
Try this for horizontal scrolling with mouse wheel. This is pure JavaScript:
(function() { function scrollHorizontally(e) { e = window.event || e; var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail))); document.getElementById('yourDiv').scrollLeft -= (delta * 40); // Multiplied by 40 e.preventDefault(); } if (document.getElementById('yourDiv').addEventListener) { // IE9, Chrome, Safari, Opera document.getElementById('yourDiv').addEventListener('mousewheel', scrollHorizontally, false); // Firefox document.getElementById('yourDiv').addEventListener('DOMMouseScroll', scrollHorizontally, false); } else { // IE 6/7/8 document.getElementById('yourDiv').attachEvent('onmousewheel', scrollHorizontally); } })();
Here’s a demo, but with document.body
and window
as a targetted element: https://taufik-nurrohman.github.io/dte-project/full-page-horizontal-scrolling.html
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