Skip to content

Instantly share code, notes, and snippets.

@fiximportant
Last active November 30, 2017 09:03
Show Gist options
  • Save fiximportant/82f446f18e9d927e50ce06e348065e36 to your computer and use it in GitHub Desktop.
Save fiximportant/82f446f18e9d927e50ce06e348065e36 to your computer and use it in GitHub Desktop.
JS Sticky
<script>
$(function(){
//begin title fixed
$(document).load($(window).bind("resize", listenWidth));
function listenWidth( e ) {
var windowWidth = $(window).width();
if (windowWidth > 767) {
stick();
}
else {
unstick();
}
}
listenWidth(); // Add this here to execute the funtion onload.
//init always
$('.js-sticky-menu').sticky(
{
topSpacing:0,
zIndex: 999,
className: 'is-sticky',
wrapperClassName: 'b-wrapper-sticky',
responsiveWidth: true,
}
);
//on stick
function stick() {
$('.js-sticky-title').sticky(
{
topSpacing:50,
zIndex: 999,
className: 'is-sticky',
wrapperClassName: 'b-wrapper-sticky',
responsiveWidth: true,
}
);
}//end stick
//off stick
function unstick() {
$('.js-sticky-title').unstick();
}//end unstick
//end title fixed
});//END READY
</script>
<div class="b-title js-sticky-title">Title</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment