jquery 用鼠标滚轮水平滚动

发布于 2024-09-01 08:26:34 字数 397 浏览 8 评论 0原文

我目前有一个横向卷轴网站 (http://www.studioimbrue.com),我尝试绑定鼠标滚轮以横向滚动。目前,我正在使用 thehorizo​​ntalway.com 上找到的一个(称为 thw.js),但它似乎不适用于所有浏览器(Chrome)。

我正在尝试让这个工作: http://brandonaaron.net/code/mousewheel/docs ,只需滚动整个窗口,仅此而已。文档非常有限,所以我无法弄清楚。任何帮助表示赞赏。

I currently have a site that is a sidescroller (http://www.studioimbrue.com) and I'm trying to bind a mousewheel to scroll sideways. Currently I'm using the one found at thehorizontalway.com (called thw.js) but it doesn't seem to work in all browsers (Chrome).

I'm trying to get this one to work: http://brandonaaron.net/code/mousewheel/docs , to simply scroll the whole window, nothing else. There is very limited documentation so I can't figure it out. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

梦里人 2024-09-08 08:26:34

我刚刚回答了关于水平滚动 div 的这个问题,我还包括一些使用鼠标滚轮或仅用鼠标抓取和拖动的代码...也许其中一些代码会给您一个想法?

详细地说,鼠标滚轮函数为您提供事件对象和增量。

$('#container').bind('mousewheel', function(event,delta){
 if (delta > 0) {
   // mousewheel is going up; 
 } else {
   // mousewheel is going down 
 }
});

delta 的值取决于您滚动滚轮的速度。如果你真的很努力的话,我已经看到了从+50到-50的范围:P

I just answered this question about scrolling a div horizontally, I also included some code to use the mousewheel or just grab and drag with the mouse... maybe some of that code will give you an idea?

To elaborate a bit, the mousewheel function gives you the event object and the delta.

$('#container').bind('mousewheel', function(event,delta){
 if (delta > 0) {
   // mousewheel is going up; 
 } else {
   // mousewheel is going down 
 }
});

The value of delta depends on how fast you scroll the wheel. I've seen a range from +50 to -50 if you try really hard :P

酒废 2024-09-08 08:26:34

我在注释中使用了 $(window).bind 方法,但它不会向后滚动,只能向前滚动,无论是在滚轮上向上还是向下滚动。

<script>
    $(window).bind('mousewheel', function(event, delta) {
        if (delta > 0) { window.scrollBy(-80,0); 
        } else window.scrollBy(80,0) ; 
    });
</script>

I used the $(window).bind approach in the comments but it wont scroll backwards, only forwards, for both up and down on the wheel.

<script>
    $(window).bind('mousewheel', function(event, delta) {
        if (delta > 0) { window.scrollBy(-80,0); 
        } else window.scrollBy(80,0) ; 
    });
</script>
爱情眠于流年 2024-09-08 08:26:34

上面评论中的解决方案有效,但仅当鼠标悬停在页面上的实际元素上时才有效。

$(window).bind('mousewheel', function(event, delta) {
    if (delta > 0) { window.scrollBy(-80,0); 
    } else window.scrollBy(80,0) ; 
});

当鼠标悬停在空白区域时(例如,如果您的内容非常短并且底部留有一些窗口),它将工作大约一个滚动,然后中断(直到您向左滚动),这就是为什么一个可能会认为滚动只有一种方式。人们为此推荐的所有花式滚动插件似乎也是这种情况。希望这可以帮助人们在未来找到解决方案。

This solution from the comments above works, but only when moused over the actual element on the page.

$(window).bind('mousewheel', function(event, delta) {
    if (delta > 0) { window.scrollBy(-80,0); 
    } else window.scrollBy(80,0) ; 
});

When just mousing over empty space (for example, if your content is very short and there's some window left over at the bottom) it'll work for about one scroll, and then break (until you scroll back left), which is why one might think that scrolling only works one way. This also seems to be the case with all of the fancy scroll plugins people recommend for this. Hopefully this helps people find a solution in the future.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文