The menu is working, but on the mobile the event is activated several times, giving the impression that the menu is stuck. This becomes more evident we change the color of the button every time the event is activated: http://codepen.io/anon/pen/oXjwWe
To solve this, you can do as in this question, using a timer to limit the time the event is activated:
$(document).ready(function() {
var active1 = false;
var active2 = false;
var active3 = false;
var active4 = false;
var flag = false;
$('.parent2').on('touchstart click', function() {
if (!flag) {
flag = true;
setTimeout(function(){ flag = false; }, 100);
if (!active1) $(this).find('.test1').css({'background-color': 'gray', 'transform': 'translate(0px,125px)'});
else $(this).find('.test1').css({'background-color': 'dimGray', 'transform': 'none'});
if (!active2) $(this).find('.test2').css({'background-color': 'gray', 'transform': 'translate(60px,105px)'});
else $(this).find('.test2').css({'background-color': 'darkGray', 'transform': 'none'});
if (!active3) $(this).find('.test3').css({'background-color': 'gray', 'transform': 'translate(105px,60px)'});
else $(this).find('.test3').css({'background-color': 'silver', 'transform': 'none'});
if (!active4) $(this).find('.test4').css({'background-color': 'gray', 'transform': 'translate(125px,0px)'});
else $(this).find('.test4').css({'background-color': 'silver', 'transform': 'none'});
active1 = !active1;
active2 = !active2;
active3 = !active3;
active4 = !active4;
}
});
});
Note that I have changed the event conditions of on
for touchstart click
. I tested on my mobile and function click
also worked without problems.
Demo: http://codepen.io/anon/pen/jPbwwg
I recommend you leave the time of the setTimeout
between 500ms and 1000ms, so it gives time the menu start to open and see it running, before it suddenly close.
It worked and with 1 more line of code, perfect. I just changed the
mousedown
forclick
by conscience.– Andrey Hartung