HTML标记:
<div class="big">
long width text
</div>
CSS规则:
.big{
height:200px;
background: red;
}
如何在鼠标滚轮http://jsfiddle.net/cxD55/
上滚动水平仅限BIG div答案 0 :(得分:2)
设置overflow-x CSS样式,但将overflow-y样式设置为可见。
答案 1 :(得分:0)
以下是解决方案:
<强> HTML 强>
<div class="big">
long text here
</div>
<强> CSS 强>
.big {
height: 200px;
overflow: hidden;
width:6000px;
}
<强> 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);
}
})();
根据您的需要更改width
。