[thelist] Finding the position of a relative DIV
Andre Dietisheim
dietisheim at gmx.net
Tue Jul 1 16:26:32 CDT 2003
Hi Chris
I put some of my codings below that work with Netscape4, IE5x, IEMac5x,
Gecko. Hope it helps...
Greets
Andrew
XlayerParent.prototype.getX = function( layer )
{
var x = 0;
// nn4up ---------------
if ( is.nn4up )
{
if ( layer != window ) x = layer.pageX;
}
// gk, iemac, iewin ---------------
else if ( is.gk || is.iemac5up || is.iewin5up )
{
currentX = 0;
if ( layer.offsetParent )
{
object = layer;
while ( object.offsetParent )
{
currentX += object.offsetLeft;
object = object.offsetParent;
}
}
else if ( layer.x )
currentX += layer.x;
x = currentX;
if ( is.iemac5up )
x += parseInt( "0" + document.body.currentStyle.marginLeft, 10 );
}
return x;
}
XlayerParent.prototype.getY = function( layer )
{
var y = 0;
// nn4up ---------------
if ( is.nn4up )
{
if ( layer != window ) y = layer.pageY;
}
// gk, iewin, iemac ---------------
else if ( is.gk || is.iewin5up || is.iemac5up )
{
currentY = 0;
if ( layer.offsetParent )
{
object = layer;
while ( object.offsetParent )
{
currentY += object.offsetTop;
object = object.offsetParent;
}
}
else if ( layer.y )
currentY += layer.y;
y = currentY;
if ( is.iemac5up )
y += parseInt( "0" + document.body.currentStyle.marginTop, 10 );
}
return y;
}
On Tue, 2003-07-01 at 17:29, Chris Evans wrote:
> Thanks, ppk, that seemed to work for me, but it led to other issues. I
> am trying to write a javascript that I can plug into any html pagewith
> no modifications, and the JS will make the images draggable wihtout
> having to make any modifications to the HTML.
>
> The problem I run into is that in order to modify the top and left
> attributes of an html element. that element has to be absolultely
> positioned. My thought was to find the existing position of the image,
> and change the style on the fly to be absolutely positioned at that same
> location. That works for the images, but it causes other html elements
> to shift on the page (tables collapse, relative postioned elements move
> around, etc).
>
> Any thoughts on how to accomplish this? Impossible, perhaps?
>
> Chris Evans
> http://www.fuseware.com
>
> --
> * * Please support the community that supports you. * *
> http://evolt.org/help_support_evolt/
>
> Evolt.org conference in London, July 25-27 2003. Register today at http://evolt.org.uk
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>
More information about the thelist
mailing list