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

时间:2013-11-15 19:31:04

标签: javascript jquery html css

jsfiddle example1 example2

我的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;
}

html代码:

<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>

1 个答案:

答案 0 :(得分:3)

使用

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

小提琴更新

http://jsfiddle.net/fc7yy/

请注意

Andy E来自这里:How to do a horizontal scroll on mouse wheel scroll?