KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to get an element's position relative to the window (fixed position). Here's what I've got so far: (function ($) { $.fn.fixedPosition = function () { var offset = this.offset(); var $doc = $(document); return { 'x': offset.left - $doc.scrollLeft(), 'y': offset.top - $doc.scrollTop() }; }; })(jQuery); $('#thumbnails img').click(function () { var pos = $(this).fixedPosition(); console.log(pos); }); But when I click a thumbnail, it appears to be off by about 10 pixels or so. i.e., it will give me negative values for y even when the top edge of the photo is about 5 pixels away from the top of my browser window.
Tags (comma-separated)
Save Edits
Cancel