Created
September 8, 2011 23:33
-
-
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
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
(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