Skip to content

Instantly share code, notes, and snippets.

@frangio
frangio / gist:846950
Created February 28, 2011 04:49
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);