简体   繁体   English

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

[英]How to scroll right and left by mouse scroll button

jsfiddle example1 example2 jsfiddle example1 example2

I have div with text inside, I want when the user will turn around the mouse scroll button ,all the div will slide to left or right insted top and down, 我的div里面有文字,我想当用户旋转鼠标滚动按钮时,所有的div都会上下左右滑动,

I try to write some code and I dont know how to continue from here. 我尝试编写一些代码,但我不知道如何从这里继续。 many thanks for any help. 非常感谢您的帮助。

this my code. 这是我的代码。

javascript code: JavaScript代码:

var valueToScroll = 0; 
$('#divScroll').bind('mousewheel', function(e){
        if(e.originalEvent.wheelDelta /120 > 0) {

            $(this).scrollLeft(++valueToScroll);
        }
        else{
            $(this).scrollRight(--valueToScroll);
        }
    });

css code: CSS代码:

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

html code: 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>

Use 采用

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

Fiddle update 小提琴更新

http://jsfiddle.net/fc7yy/ http://jsfiddle.net/fc7yy/

Please credit 请相信

Andy E from here: How to do a horizontal scroll on mouse wheel scroll? Andy E从这里开始: 如何在鼠标滚轮上水平滚动?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM