簡體   English   中英

與鼠標輪的水平的紙卷在水平的名單上

[英]Horizontal scroll with mouse wheel on horizontal list

我正在嘗試用鼠標滾輪進行水平滾動,但似乎不起作用。

這是我的小提琴

我的主類.selector是具有可滾動overflow.selector

這是JS我試圖初始化滾動

 $('.selector').mousewheel(function(e, delta) {
    this.scrollLeft -= (delta * 40);
    e.preventDefault();
});

這是我用於水平滾動的示例https://css-tricks.com/snippets/jquery/horz-scroll-with-mouse-wheel/

在此先感謝您的幫助!

編輯:謝謝大家,我忘記了小提琴中的jQuery對不起,但是當我在localhost上測試時,我使用的是jQuery 1.11.1,所以也許就是這種情況。 干杯伙計們

你只是忘了將JQuery添加到你的HTML

http://jsfiddle.net/902tjbzz/

jquery.jshttp//code.jquery.com/jquery-2.1.4.min.js

試試這個

$('.selector').mousewheel(function(e, delta) {
    $(this).scrollLeft(this.scrollLeft + (-delta * 40));
    e.preventDefault();
});

此外,你沒有在你的小提琴中包含jQuery。

編輯

實際上,唯一的問題是你沒有包含jQuery,你的初始代碼運行正常。

第一件事:在yor jsfiddle中你忘了包含jquery。

第二件事:我更改了$('.selector').mousewheel(function(e, delta) {$('.selector').on("mousewheel", function(e, delta) {然后我才能看到該事件被觸發。

另請檢查您的scrollLeft屬性更新邏輯。 不要忘記方向(左,右),所以在某些情況下你應該添加減去它的值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM