Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用触摸设备触发鼠标滚轮事件_Javascript_Jquery_Touch_Mousewheel - Fatal编程技术网

Javascript 使用触摸设备触发鼠标滚轮事件

Javascript 使用触摸设备触发鼠标滚轮事件,javascript,jquery,touch,mousewheel,Javascript,Jquery,Touch,Mousewheel,我有一个绑定到mousewheel的事件,在其中我使用该事件进行一些计算,我希望能够使用相同的功能从触摸设备执行相同的计算 我的代码如下: $('#element').bind("mousewheel DOMMouseScroll", function(event) { event.preventDefault(); if (event.originalEvent.wheelDelta > 0 || event.originalEvent.d

我有一个绑定到mousewheel的事件,在其中我使用该事件进行一些计算,我希望能够使用相同的功能从触摸设备执行相同的计算

我的代码如下:

$('#element').bind("mousewheel DOMMouseScroll", function(event) {
            event.preventDefault();
            if (event.originalEvent.wheelDelta > 0 || event.originalEvent.detail < 0)
                //do stuff
            else {
               //do other stuff
            }
        });
$(“#元素”).bind(“mousewheel-DOMMouseScroll”,函数(事件){
event.preventDefault();
if(event.originalEvent.wheelDelta>0 | | event.originalEvent.detail<0)
//做事
否则{
//做其他事情
}
});

编辑:从评论中我了解到我并不完全清楚,我的目标是获得一个像“wheelDelta”这样的值,让我能够识别用户是否在上下滚动(触摸移动)

这可能不是合适的解决方案,但您可以这样做

  var lastScroll = 0;

  $('#element').on("scroll", function() {
    var st = $(this).scrollTop();
    if (st > lastScroll){
       // downscroll code
       //$(this).trigger("mousewheeldown");
    } else {
      // upscroll code
      //$(this).trigger("mousewheelup");
    }
    lastScroll = st;
    $(this).trigger("mousewheel");
  });

我希望这会有所帮助:)

这可能不是合适的解决方案,但您可以这样做

  var lastScroll = 0;

  $('#element').on("scroll", function() {
    var st = $(this).scrollTop();
    if (st > lastScroll){
       // downscroll code
       //$(this).trigger("mousewheeldown");
    } else {
      // upscroll code
      //$(this).trigger("mousewheelup");
    }
    lastScroll = st;
    $(this).trigger("mousewheel");
  });

我希望这能有所帮助:)

触摸设备没有
鼠标滚轮
事件。也许你应该尝试一起使用
mousemove
touchmove
?你可以试试我的插件。它适用于鼠标、触摸和滚轮事件。触摸设备没有
mouseweel
事件。也许你应该尝试一起使用
mousemove
touchmove
?你可以试试我的插件。它适用于鼠标、触摸和滚轮事件。为什么他们会这样做?他基本上可以检测一个用户生成的事件并手动触发另一个。根据我的理解,这基本上就是他想要的。没有点击我的代码,我不明白为什么我会尝试像你建议的那样。我想你需要听滚动事件而不是点击并触发鼠标滚轮而不是滚动。我需要知道滚动的方向为什么他们会这样做?他基本上可以检测到一个用户生成的事件并手动触发另一个。根据我的理解,这基本上就是他想要的。没有点击我的代码,我不明白为什么我会尝试像你建议的那样。我想你需要听滚动事件而不是点击并触发鼠标滚轮而不是滚动。我需要知道滚动的方向