removeClass not working on iOS

前端 未结 2 1633
伪装坚强ぢ
伪装坚强ぢ 2021-01-24 05:04

When you click .menuButton jquery will add a class named active. This Jquery code works on Windows and on Android except on iOS (Tested with Chrome an

相关标签:
2条回答
  • 2021-01-24 05:36

    try this

    $(document).ready(function() {
      var $ua = navigator.userAgent;
      var $event = ($ua.match(/(iPod|iPhone|iPad)/i)) ? "touchstart" : "click";
    
      $(document).on($event, function(ev) {
        if ($('.navmenu').hasClass('active')) {
          $('.navmenu').toggleClass('active');
        }
      });
      $('.menuButton').on('click', function(e) {
        e.stopPropagation();
        $('.navmenu').toggleClass('active');
      });
    });
    

    http://codepen.io/fabiovaz/pen/VaPzqz

    I really think your problems is $('html').click() on iOS, you can search other solutions (like touch actions) or check if this work $('html').click(function() { alert('hello world'); });

    var ua = navigator.userAgent,
            event = (ua.match(/iPad/i)) ? "touchstart" : "click";
    
    $(document).on(event, function (ev) {
        ...
    });
    
    0 讨论(0)
  • 2021-01-24 05:58

    Can you try this ?

    see here https://jsfiddle.net/dkg7tyu0/1/

    if (!$('.navmenu').hasClass('active')) {
            $('.navmenu').addClass('active');
          removeClass = false;
        }       
    
    0 讨论(0)
提交回复
热议问题