views:

44

answers:

1

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?

A: 

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

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

mporkola
Now rightClick() and leftClick() methods are not firing
coure06