[英]issue with horizontal wheel scroll
我有一個模板,當用戶使用鼠標滾輪時,模板會水平滾動。
但它僅適用於chrome。
有什么辦法可以在firefox和IE中水平滾動?
這是一個演示: http : //jsfiddle.net/VhERd/
和jquery:
<script>
$(function() {
$("body").mousewheel(function(event, delta) {
this.scrollLeft -= (delta * 30);
event.preventDefault();
});
});
</script>
<script src="http://css-tricks.com/examples/HorzScrolling/jquery.mousewheel.js"></script>
最后請我說英語;)
它需要處理html
元素,而不是Firefox的body
元素。
$("body, html").mousewheel....
我已經使用了此功能,雖然有點笨拙,但是可以完成工作。
function scrollPage (e) {
var delta = e.deltaX || e.wheelDelta,
dir = (delta > 0) ? -90 : 90;
if (window.addEventListener && !(window.chrome || window.opera)) {
dir *= -1;
}
window.scrollBy(dir, 0);
e.returnValue = false;
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
並附上事件:
if (window.addEventListener && (!window.chrome && !window.opera)) {
window.addEventListener('wheel', scrollPage, false); // IE9+, FF
} else if (window.chrome || window.opera) {
window.addEventListener('mousewheel', scrollPage, false); // Chrome & Opera
} else {
document.attachEvent('onmousewheel', scrollPage); // IE8-
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.