I have a nav that opens on hover.
I wish to make this work with touch devices.
SASS:
.menu{
&:hover, .hover{
top: 300px;
}
}
JQUERY:
$('.menu').on('touchstart', function(e) {
e.preventDefault();
if ($(this).hasClass('hover')) {
$(this).removeClass('hover');
} else {
$(this).addClass('hover');
$('.menu').not(this).removeClass('hover');
}
});
So the above should, on touch, add a hover class to the menu class if it does not have one, and remove all other hover classes. If it does have a hover class, I then wish to remove it.
The code works apart from, removing the hover class if it already has a hover class.
I suspect this is due to the phone interpreting the :hover.
How can I prevent touch devices from interpreting the :hover?
Im not using jquery mobile.