Last active
December 14, 2015 01:38
-
-
Save ahmednasir91/5007168 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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