如何通过鼠标滚动按钮左右滚动



jsfiddle example1例2

我里面有文字的div,我希望当用户转动鼠标滚动按钮时,所有div都会向左或向右滑动而是自上而下,

我尝试编写一些代码,但我不知道如何从这里继续。非常感谢任何帮助。

这是我的代码。

JavaScript代码:

var valueToScroll = 0; 
$('#divScroll').bind('mousewheel', function(e){
        if(e.originalEvent.wheelDelta /120 > 0) {
            $(this).scrollLeft(++valueToScroll);
        }
        else{
            $(this).scrollRight(--valueToScroll);
        }
    });

CSS代码:

div{
    width:2000px;
    height:100px;
    background:red;
}

网页代码:

<div id="divScroll">There is a substantial disparity of 13-17% between the earnings of men and women in the same positions and at similar skill levels, according to a new study by the National Insurance Institute, seeking to examine the socio-economic status of women in Israel between in the years 1997-2011.
</div>

使用

 document.body.doScroll(event.wheelDelta>0?"left":"right");

小提琴更新

http://jsfiddle.net/fc7yy/

请注明

安迪E从这里: 如何在鼠标滚轮滚动上进行水平滚动?

最新更新