1
基於此:http://reader-download.googlecode.com/svn/trunk/full-page-horizontal-scrolling.html我不能在我的生活中使它在IE 10中以標準模式或怪癖模式工作。我在這裏有一個jsFiddle,但它只能垂直滾動:http://jsfiddle.net/dwsRC/1/JavaScript:水平滾動鼠標滾輪
滾動代碼與示例網站的100%相同。我嘗試了其他滾動樣本,但防止默認不起作用。添加jQuery也無濟於事。
在Visual Studio 2012,我得到:
JavaScript runtime error: Object doesn't support property or method 'preventDefault'
HTML:
<div id="container">
<div class="content c1">Hello, World!</div>
<div class="content c2">Hello, World!</div>
<div class="content c3">Hello, World!</div>
<div class="content c1">Hello, World!</div>
<div class="content c2">Hello, World!</div>
<div class="content c3 last">Hello, World!</div>
</div>
CSS:
#container {
height: 100%;
width: 6000px;
overflow: hidden;
}
.content {
width: 895px;
height: 675px;
float:left;
margin-right:50px;
}
.c1 {
background-color: red;
}
.c2 {
background-color: blue;
}
.c3 {
background-color: green;
}
JS:
(function() {
function scrollHorizontally(e) {
e = window.event || e;
var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
document.body.scrollLeft -= (delta * 40); // Multiplied by 40
e.preventDefault();
}
if (window.addEventListener) {
// IE9, Chrome, Safari, Opera
window.addEventListener("mousewheel", scrollHorizontally, false);
// Firefox
window.addEventListener("DOMMouseScroll", scrollHorizontally, false);
} else {
// IE 6/7/8
window.attachEvent("onmousewheel", scrollHorizontally);
}
})();