The following functions work, but it doesn't look clean and there is probably a better way to achieve what I've done. Here is what I'm trying to do:
If the viewport is resized, even by 1px, the styles for the mobile button are removed. Also, the class 'active' is removed.
On click the 'mobile-nav' element is displayed and slides down and 'active' class is added.
I try not to rely on CSS3, I'm trying to get aa :hover transition working. So when I hover over the .menu-button
it smoothly transitions to the .menu-button:hover
styles.
// Mobile Menu Button
$(window).resize(function () {
$(".menu-button").removeClass("active");
});
$(window).resize(function () {
$(".mobile-nav").removeAttr("style");
});
$(".menu-button").click(function () {
$(".menu-button").toggleClass("active");
});
$(".menu-button").click(function () {
$(".mobile-nav").slideToggle(250);
});
You are attaching to functions at the same events (window resize and menu-button click), is better to call the two functions in the same event handler like:
// Mobile Menu Button
$(window).resize(function () {
$(".menu-button").removeClass("active");
$(".mobile-nav").removeAttr("style");
});
$(".menu-button").click(function () {
$(".menu-button").toggleClass("active");
$(".mobile-nav").slideToggle(250);
});
Here is a fiddle: http://jsfiddle.net/IrvinDominin/Sm5zy/12/
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.