Max*_*cov 6 javascript macos jquery mousewheel inertiajs
我需要像jquery.fullPage那样组织导航:当我滚动一次时 - 我转到下一部分.
我尝试使用jquery.mousewheel,但它在带有触摸板或触控板或APPLE Magic Mouse的MacOS中失败:它每个滚动滚动多个幻灯片.
我试图使用这个解决方案:https://github.com/jquery/jquery-mousewheel/issues/36#issuecomment-67648897
它在Chrome中运行良好,但它不在FF中并且在Safari中存在错误.
这是问题的简单演示:http: //jsfiddle.net/ss5LueLx/13/
$slider.on('mousewheel', function(event) {
if (event.deltaY>0) {
slider.prevSlide();
} else {
slider.nextSlide();
}
});
Run Code Online (Sandbox Code Playgroud)
我在 SeaMonkey 浏览器中测试了此语句,但失败了。
var delta = e.type == 'mousewheel' ? e.originalEvent.wheelDelta * -1 : 40 * e.originalEvent.detail;
Run Code Online (Sandbox Code Playgroud)
为了以防万一,我查看了 deltaY,它的工作原理是:一个方向为 +1,另一个方向为 -1,正如您在其他两个实现中所确定的那样。
console.log(e.deltaY); // view console in FireBug
Run Code Online (Sandbox Code Playgroud)
查看Firebug中的事件结构,我可以看到事件类型是“mousewheel”,但我在originalEvent中没有看到wheelData字段。
尽管有一个详细信息字段,但该字段仍为零。
我想您只有在达到 +/-3 时才会尝试转到下一个项目。我建议采取类似的措施来完成这一壮举:
// somewhere, initialize to zero
var current_position = 0;
// on mousewheel events
current_position += e.deltaY;
// you had a x 40 which would indicate that the limit is about 120 / 40
// if 3 is too small, you can always increase it to 5 or event 10...
if(current_position <= -3)
{
slider.nextSlide();
current_position = 0;
}
else if(current_position >= 3)
{
slider.prevSlide();
current_position = 0;
}
Run Code Online (Sandbox Code Playgroud)
否则,您可以验证您的allowScroll标志是否按预期工作。我不以这种方式编程对象,所以我不太确定它是否正确。(prototype如果你想扩展类,我使用的语法很有用。)