简体   繁体   中英

Combining Sidr menu with animated hamburger button

My test page https://osticketawesome.com/support/awesome/inc/test.html

I'm trying to combine a hamburger menu with the Sidr jQuery plugin for creating side menus.

It works perfectly in Chrome, FF, IE and Edge but in the mobile browsers I've tested (Android/Chrome and iPhone/Safari) the menu toggles but the button only animates if I tap on the outside edge of the button.

<div id="header">
    <div id="right-menu" href="#right-menu">
        <button href="#right-menu" class="c-hamburger c-hamburger--htx">
            <span>toggle menu</span>
        </button>
    </div>
</div>  

$(document).ready(function() {
    var toggles = document.querySelectorAll(".c-hamburger");
    for (var i = toggles.length - 1; i >= 0; i--) {
      var toggle = toggles[i];
      toggleHandler(toggle);
    };
    function toggleHandler(toggle) {
      toggle.addEventListener( "click", function(e) {
        e.preventDefault();
        (this.classList.contains("is-active") === true) ?
            this.classList.remove("is-active") : 
            this.classList.add("is-active");
      });
    }
   $('.c-hamburger').sidr({
        name: 'right_menu',
        side: 'right',
        body: 'container'
    }); 
})();

Any ideas?

I just solved this. In case it helps anyone later on, I simply doubled-up on the following function:

function toggleHandler(toggle) {
  toggle.addEventListener( "click", function(e) {
    e.preventDefault();
    (this.classList.contains("is-active") === true) ? this.classList.remove("is-active") : this.classList.add("is-active");
  });
  toggle.addEventListener( "touchstart", function(e) {
    e.preventDefault();
    (this.classList.contains("is-active") === true) ? this.classList.remove("is-active") : this.classList.add("is-active");
  });     
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM