Skip to content

Instantly share code, notes, and snippets.

@ahmednasir91
Last active December 14, 2015 01:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmednasir91/5007168 to your computer and use it in GitHub Desktop.
Save ahmednasir91/5007168 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
$(document).ready(function () {
//checks if the number of posts on this page are more than one then return.
if($('.post-outer').length > 1)
return;
//selects the element to be made sticky.
var stickElement = $('.date-header'),
//selects the element which would trigger the sticky elem to go away
hideTrigger = $('#comments'),
//class name to be added (it should match the class in CSS)
fixed = "fixed",
top = stickElement.offset().top;
$(window).scroll(function (event) {
var y = $(this).scrollTop();
var maxY = hideTrigger.offset().top;
if (y >= top && y < maxY) {
stickElement.addClass(fixed);
} else {
stickElement.removeClass(fixed);
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment