Touch device, Single and Double Tap Events handler jQuery/Javascript?

后端 未结 4 1551
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 00:50

Background:

My site is in magento open source ecommerce solution, and in the top (header) it has a shopping cart icon. On dekstop, when user hovers

4条回答
  •  遥遥无期
    2020-12-13 01:27

    this is my hack. It's a small code block and it should work well on mobiles. It sets a timer when you first tap on something and then it checks if the second tap is in the time range (600ms in this example)

        // DOUBLE TAP
        var timer = 0;
        $(document).on("click" , "#target" , function() {
            if(timer == 0) {
                timer = 1;
                timer = setTimeout(function(){ timer = 0; }, 600);
            }
            else { alert("double tap"); timer = 0; }
        });
    

提交回复
热议问题