JavaScript - mousemove event not triggered on iPad/iPhone

只谈情不闲聊 提交于 2019-12-13 07:19:34

问题


I worked for a while on E-learning project, where I had to script an HTML file that's loaded on a global framework. I used to use:

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

And it worked well everywhere (Chrome, IE, iOS ... etc)

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).

Here is simple code I wrote, that doesn't work on an 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 ?


回答1:


Just use 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/



来源:https://stackoverflow.com/questions/14071285/javascript-mousemove-event-not-triggered-on-ipad-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!