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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…