简体   繁体   English

JavaScript - 在iPad / iPhone上未触发mousemove事件

[英]JavaScript - mousemove event not triggered on iPad/iPhone

I worked for a while on E-learning project, where I had to script an HTML file that's loaded on a global framework. 我在电子学习项目上工作了一段时间,我必须编写一个加载到全局框架上的HTML文件。 I used to use: 我以前用过:

$('#myobject').on('mousedown' ... 'mousemove' ... 'mouseup' , function(){} ) $('#myobject').on('mousedown' ... 'mousemove' ... 'mouseup' , function(){}

And it worked well everywhere (Chrome, IE, iOS ... etc) 它在各处都运行良好(Chrome,IE,iOS等)

Now I am working on a personal project, and in the browser everything is working well, but 'mousemove' does not seem to get triggered on iDevices (iPad, iPhone ... etc). 现在我正在开发一个个人项目,在浏览器中一切都运行良好,但是'mousemove'似乎没有在iDevices(iPad,iPhone等)上触发。

Here is simple code I wrote, that doesn't work on an iPad: 这是我写的简单代码,在iPad上不起作用:

$(window).load(function() {

        document.ontouchmove = function(e){
            e.preventDefault(); 
        }   

        $(document).on('mousemove',onmm);
        function onmm(e){
            var a = e.pageX;
            var b = e.pageY;
            $('#txt1').html(a);
            $('#txt2').html(b);
        }

    });

Any help ? 有帮助吗?

Just use jquery.event.move. 只需使用jquery.event.move。 Move events provide an easy way to set up press-move-release interactions on mouse AND touch devices. 移动事件提供了一种在鼠标和触摸设备上设置按下 - 移动 - 释放交互的简便方法。 So you don't have to worry which device your users have. 因此,您不必担心用户使用的设备。

Source and examples: http://stephband.info/jquery.event.move/ 来源和示例: http//stephband.info/jquery.event.move/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM