Created
May 3, 2016 21:24
-
-
Save sezgi/76d3214b27c50a61b7f02d32e5513d0c to your computer and use it in GitHub Desktop.
Hamburger nav
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// using http://johnm.io/project/hamburgler/ | |
$(function () { | |
var open = false; | |
function toggleScroll () { | |
if (open) { | |
$('.body-wrap').height($('.hamburger-nav')[0].scrollHeight).css('overflow', 'hidden'); | |
} else { | |
$('.body-wrap').height('auto').css('overflow', 'visible'); | |
} | |
} | |
$(".hamburger-icon").click(function () { | |
open = !open; | |
toggleScroll(); | |
$(".body-wrap").toggleClass("animate"); | |
$('.hamburger-nav').toggleClass("animate"); | |
$(".hamburger-top").toggleClass("top-animate"); | |
$(".hamburger-mid").toggleClass("mid-animate"); | |
$(".hamburger-bottom").toggleClass("bottom-animate"); | |
}); | |
function undo () { | |
if (open) { | |
open = false; | |
toggleScroll(); | |
$(".body-wrap").removeClass("animate"); | |
$('.hamburger-nav').removeClass("animate"); | |
$(".hamburger-top").removeClass("top-animate"); | |
$(".hamburger-mid").removeClass("mid-animate"); | |
$(".hamburger-bottom").removeClass("bottom-animate"); | |
} | |
} | |
// ESC key | |
$(document).keydown(function(e) { | |
if (e.keyCode == 27) { | |
undo(); | |
} | |
}) | |
$(window).on('resize', function () { | |
if ($(window).width() >= 768) { | |
undo(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment