stopPropagation() with tap event

后端 未结 5 1850
[愿得一人]
[愿得一人] 2021-02-15 02:12

I\'m using hammer.js and it appears that I event.stopPropagation() doesn\'t work with tap event.

If I click on the child, the associated event is triggered

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-15 03:03

    As I couldn't get this work, I used a variable to know if the child event has already been triggered. It works quite well with jGestures (I have not tried with hammer.js)

    var childTriggered = false;
    
    $('#child').bind('tapone', function(e) {
        $(this).css('background', 'red');
        childTriggered = true;
    });
    
    $('#parent').bind('tapone', function(e) {
        if(childTriggered) {
            childTriggered = false;
            return;                
        }
        $(this).css('background', 'blue');
    });
    

提交回复
热议问题