JavaScript - mousemove event not triggered on iPad

2019-09-06 08:32发布

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条回答
forever°为你锁心
2楼-- · 2019-09-06 09:09

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/

查看更多
登录 后发表回答