Skip to content

Instantly share code, notes, and snippets.

@iledcom
Last active February 15, 2017 10:17
Show Gist options
  • Save iledcom/d4b287a2209e5b8b138059ea50605023 to your computer and use it in GitHub Desktop.
Save iledcom/d4b287a2209e5b8b138059ea50605023 to your computer and use it in GitHub Desktop.
Fixed menu (a selector) when the page scrolls
//common.js
$(function() {
$(window).scroll(function() {
var the_top = $(document).scrollTop();
if (the_top > 1) {
$('.site-navigation-wrap').addClass('fixed-menu');
}
else {
$('.site-navigation-wrap').removeClass('fixed-menu');
}
});
});
//index.html
<div class="site-navigation-wrap"></div>
//style.sass
.site-navigation-wrap
min-height: 48px
background: $headers-color
position: relative
.fixed-menu
position: fixed
top: 0
left: 0
right: 0
margin: 0
z-index: 500
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment