Jump to content

[SOLVED] Finding offsets of dynamic content


FrostiE

Recommended Posts

Hey,

 

One of the things I'm trying to get working at the moment is dynamic thumbnailing. Basically the user has the choice for a auto thumbnail (crop to 1:1 proportion ratio, and resize) or a manual thumbnail.

 

http://ewanfrost.com/modman/thumbnail.php -> (haven't tried IE compatibility yet, since its just a tech test)

 

ajax.jpg

 

Ok, so I'm trying to test it in some kinda gallery environment (picture above). By click on the image, if makes a absolute positioned DIV appear, and loads dynamic content (the larger image and scroller) using Prototype's AJAX.Updater function. The problem is, if I try and find the the left position of the image offsetLeft, it returns 0. I assume this is because its 0 px away from the side of the div.

 

Does anyone know how I could insert it into the DOM where it is considered part of the document and the calculations will involve the whole document, if not, any suggestions and ideas would be great.

 

Thanks!

 

 

 

 

 

Link to comment
Share on other sites

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
         curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

 

http://www.quirksmode.org/js/findpos.html

--works great, I use it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.