Javascript / jQuery - Tap outside an element on an iPhone

后端 未结 2 547
萌比男神i
萌比男神i 2021-02-10 15:40

I found a great answer on detecting a click outside a div from this question: How do I detect a click outside an element?, which works fantastically.

But I\'ve noticed

相关标签:
2条回答
  • 2021-02-10 16:07
    var doc = document.documentElement;
    doc.addEventListener('click', function (e) { //TODO();});
    

    The trick:

    /*Add this line into only mobile css*/
    body{cursor:pointer}
    
    0 讨论(0)
  • 2021-02-10 16:17

    this worked for me :)

    $('html').on('touchstart', function(e) {
        $('.navbar-flyout').hide();
    })
    $(".navbar-flyout").on('touchstart',function(e) {
        e.stopPropagation();
    });
    
    0 讨论(0)
提交回复
热议问题