简体   繁体   中英

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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