Combining Sidr menu with animated hamburger button

by stevland   Last Updated February 07, 2016 12:43 PM

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.

enter image description here

<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?



Answers 1


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");
  });     
}
stevland
stevland
February 07, 2016 07:21 AM

Related Questions


Some advanced styling I know nothing about

Updated April 28, 2016 08:01 AM


Animation on hover

Updated February 06, 2019 20:04 PM

Can I freeze all moving images in my browser?

Updated July 21, 2019 13:04 PM