简体   繁体   中英

cancelling default touchmove event

i have created a little slide show in jQuery. On clicking-n-dragging your mouse it shows next/previous slide. I have added special code for dealing with iphone. But on iphone (safari) when i move my finger over the object the whole page is dragged left-right. here is the code

        var oldX = 0;
        $('#movieShow').bind('touchstart',function(e){                  
                if(e.touches.length == 1){
                    var touch = e.touches[0];
                    oldX = touch.pageX;
                }
                return false;
            }).bind('touchmove',function(e){                
                if(e.touches.length == 1){
                    var touch = e.touches[0];
                    if((touch.pageX - oldX) > 0){
                        var t = touch.pageX - oldX;
                        if(t%5==0){
                            oldX = touch.pageX;
                            rightClick();
                        }
                    }
                    else{
                        var t = oldX - touch.pageX;
                        if(t%5==0){
                            oldX = touch.pageX;
                            leftClick();
                        }
                    }
                }
                return false;
            });         

how do i cancel defaults iphone event?

您可以使用event.preventDefault();

Try adding this to the beginning of your function: e.preventDefault();

More info here: http://api.jquery.com/event.preventDefault/

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