iPad/iPhone double click problem

前端 未结 3 664
星月不相逢
星月不相逢 2021-02-04 21:51

I\'m having a very similar problem to iPad/iPhone hover problem causes the user to double click a link where a user tapping a link has to tap twice to actually go to it.

<
3条回答
  •  遥遥无期
    2021-02-04 22:40

    Here's what I ended up doing:

    The problem is that touchstart and touchend only know about touch events, not scroll events, so they only react to starting the touch and ending the touch. What we have to do is distinguish between scrolling and not scrolling. Here's what I did:

    $('a')
        .live('touchstart', function(){
            isScrolling = false;
        })
        .live('touchmove', function(e){
            isScrolling = true;
        })
        .live('touchend', function(e){
            if( !isScrolling )
            {
                window.location = $(this).attr('href');
            }
        });
    

    This does these things in order:

    1. When touch is first recorded, set isScrolling to false.
    2. When touch is moved, set isScrolling to true. This will not happen if the touch doesn't move.
    3. When touch is stopped, if scrolling has not happened, redirect the page to the link's href.

    Edit: A while after this, I discovered the problem was being caused by SuperFish. Disabling superfish when the page was under a certain width solved the problem.

提交回复
热议问题