Skip to content

Instantly share code, notes, and snippets.

@craigmdennis
Created September 8, 2011 23:33
Show Gist options
  • Save craigmdennis/1205097 to your computer and use it in GitHub Desktop.
Save craigmdennis/1205097 to your computer and use it in GitHub Desktop.
Get the current position of an element relative to the top of the viewport
(function ($) {
$.fn.currentScrollPos = function () {
var obj = this.offset().top;
obj = obj - window.pageYOffset;
return obj;
}
})(jQuery);
$(window).scroll(function () {
console.log($('#your-element').currentScrollPos());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment