1

这个Js fiddle描述了我遇到的问题。

我在我的网站中使用Nice Scroll插件。它工作正常。

但在一页中,我必须显示宽度接近 1000 像素的时间线。客户想要平滑地向下滚动直到时间线。

当鼠标指针位于时间线 div 中时,滚动条应水平移动。

我已将此代码添加到该站点。

document.getElementById('tl-scroll').addEventListener('mousewheel', function(e) {
  this.scrollLeft -= (e.wheelDelta);
  e.preventDefault();    
}, false);

似乎preventDefault无法与nicescroll.

请帮我清除此错误。

4

1 回答 1

1

你只需要使用 usereturn false;而不是e.preventDefault();

试试这个更新的 Js 代码:

$(document).ready(function() { 
    $("html").niceScroll();
}); 

// You missed to close it properly above. Syntax error.      

document.getElementById('tl-scroll').addEventListener('mousewheel', function(event) {
  this.scrollLeft -= (event.wheelDelta);
  console.log('I have stopped it');
  return false; // Instead of e.preventDefault(); you just need to use "return false;"
}, false);
$('#tl-scroll').getNiceScroll().hide();

你给定的小提琴有控制台问题和jquery库加载问题。我已经修好了,看看我的工作小提琴

我想建议您使用HERE中的 CDN 引用来进行小提琴演奏。

希望这可以帮助 :)

于 2015-07-14T06:57:35.230 回答