- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Navigation displays block after multiple resizes
When I resize the screen everything works correctly. But once I resize again, it doesn’t work the way I want it to.
The navigation li appears as block elements when I want them to display none unless I click on menu.
Like this?
What you describe happens because .show()
adds display: block
as inline style. And it’s overriding the CSS you defined for it with that. I’ve just put a .hide()
in the else
condition. Also cached the $('nav ul')
selector since it’s used quite a few times.
Perfect. Thank you for the help
function throttle (callback, limit) {
var wait = false; // Initially, we’re not waiting
return function () { // We return a throttled function
if (!wait) { // If we’re not waiting
callback.call(); // Execute users function
wait = true; // Prevent future invocations
setTimeout(function () { // After a period of time
wait = false; // And allow future invocations
}, limit);
}
}
}
$(window).on(‘resize’, throttle(yourResizeFunction, 200))