I made this "slide-out" menu: SASS Slide-out Menu .
It's ok, but I want that when the menu have slid, on window click the menu returns back(remove the class "nav-open").
I tried this on the codepen demo, but it doesn't work:
window.on("click", function(e) {
if(wrapper.hasClass("nav-open") && e.target != nav && e.target.parent() != nav) {
wrapper.removeClass("nav-open");
}
});
You're close! I think your codepen example needs the close logic block tweaking to look like this:
$(window).on("click", function(e) {
if (
wrapper.hasClass("nav-open") &&
!$(e.target).parents(nav).hasClass("side-nav") &&
!$(e.target).hasClass("toggle")
) {
wrapper.removeClass("nav-open");
}
});
Some tips for you:
Forked codepen with working code: http://codepen.io/anon/pen/mzAru
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.