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 and Safari).
HTML5
<div class="menuButton">
Menu Button
</div>
<div class="navmenu">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">Something</a></li>
</ul>
</div>
Jquery
var removeClassVar = true;
$('.menuButton').on('click', function() {
$('.navmenu').toggleClass('active');
removeClassVar = false;
});
$('.navmenu').on('click', function() {
removeClassVar = false;
});
$(document).on('click', function() {
if (removeClassVar == true) {
$('.navmenu').removeClass('active');
}
removeClassVar = true;
});
CSS3
.menuButton {
display:block;
cursor:pointer;
}
.navmenu {
display:none;
}
.navmenu.active {
display:block;
}
Problem: When you click on .menuButton
the menu will show, but when you click on html
the menu will not run removeClass('active')
. This problem only occurs on iOS.
JsFiddle: https://jsfiddle.net/dkg7tyu0/
Updated JSFiddle: https://jsfiddle.net/dkg7tyu0/5/
Update
Apparently iOS does not work with on('click'')
however adding the following code will get me a Hello World $('.menuButton').on('touchstart click', function(){ alert('hello world'); });
. Bad news is that changing my code from on('click')
to on('touchstart click')
will not make a difference in removing the class.