Skip to content

Instantly share code, notes, and snippets.

@Caaz
Created February 21, 2017 21:53
Show Gist options
  • Save Caaz/ed1baedfb6ada267c9e0dbca34709f65 to your computer and use it in GitHub Desktop.
Save Caaz/ed1baedfb6ada267c9e0dbca34709f65 to your computer and use it in GitHub Desktop.
$(document).scroll(function(e){
var $window = $(window)
var $authors = $('.author')
if($authors.length > 0) {
$authors.each(function(i, e) {
var $author = $(e)
var $container = $author.parent().parent()
var offset = Math.max(0, $window.scrollTop() - $container.offset().top + 50)
offset = Math.min($container.height() + $container.offset().top - $author.outerHeight() - 50, offset)
var currentOffset = parseFloat($author[0].style.top)
if(offset !== currentOffset) {
$author.css({top:offset})
}
})
}
}).scroll()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment