removeClass not working on iOS

前端 未结 2 1636
伪装坚强ぢ
伪装坚强ぢ 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) {
        ...
    });
    

提交回复
热议问题