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!

 

 

 

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.