Skip to content

Instantly share code, notes, and snippets.

@frangio
Created February 28, 2011 04:49
Show Gist options
  • Save frangio/846950 to your computer and use it in GitHub Desktop.
Save frangio/846950 to your computer and use it in GitHub Desktop.
a jquery method to get the position of an object relative to the viewport (doesn't work that well sometimes, because of merged margins and such)
(function($) {
$.fn.viewportPosition = function() {
var a = this, b = a.offset().top - $(window).scrollTop(), c = a.offset().left - $(window).scrollLeft();
return {top: b, left: c};
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment