js script for div positioning working not like I expected...

R

Randell_D

Folks,
My script below near-works on both Firefox2 and IE7 (though my end
user base will be Firefox2 intranet users only)... "near-works" means
it does permit me to place my div tag on the screen but not where I
expect.

returnLocation() appears to work - it gives me different numeric
results depending on the location of my id tag'd url.

When I pass these numeric values to place() I would expect that my new
output would overwrite the old output but instead its written
somewhere else on the screen. Can someone tell me why this is the
case?

Cheers!


function place( tagID, across, down )
{
var pointer=returnTagObject( tagID );
pointer.style.position="absolute";

if( across<1 )
{ pointer.style.left = ( pointer.offsetWidth+parseFloat(across) ) +
"px"; }
else
{ pointer.style.left = ( pointer.offsetWidth+across ) + "px"; }

if( down<1 )
{ pointer.style.top = ( pointer.offsetHeight+parseFloat(down) )
+"px"; }
else
{ pointer.style.top = ( pointer.offsetHeight+down ) +"px"; }
return;
}

function returnLocation( tagID )
{ // Return (as a string) the location of tagID (use parseFloat to
reverse it back into integer)
var pointer=returnTagObject( tagID );
return pointer.offsetWidth+":"+pointer.offsetHeight;
}
 
D

Doug Gunnoe

Folks,
My script below near-works on both Firefox2 and IE7 (though my end
user base will be Firefox2 intranet users only)... "near-works" means
it does permit me to place my div tag on the screen but not where I
expect.

returnLocation() appears to work - it gives me different numeric
results depending on the location of my id tag'd url.

When I pass these numeric values to place() I would expect that my new
output would overwrite the old output but instead its written
somewhere else on the screen.  Can someone tell me why this is the
case?

Cheers!

function place( tagID, across, down )
{
  var pointer=returnTagObject( tagID );
  pointer.style.position="absolute";

  if( across<1 )
  {     pointer.style.left = ( pointer.offsetWidth+parseFloat(across) ) +
"px"; }
        else
  {     pointer.style.left = ( pointer.offsetWidth+across ) + "px";   }

  if( down<1 )
  {     pointer.style.top = ( pointer.offsetHeight+parseFloat(down) )
+"px";                }
  else
  {     pointer.style.top = ( pointer.offsetHeight+down ) +"px";      }
  return;

}

function returnLocation( tagID )
{       // Return (as a string) the location of tagID (use parseFloat to
reverse it back into integer)
        var pointer=returnTagObject( tagID );
        return pointer.offsetWidth+":"+pointer.offsetHeight;



}- Hide quoted text -

- Show quoted text -
A couple of questions.

So you want a DIV to move to where the user clicks?

Why do you use parseFloat on the if case and not the else? I know that
string concatenation versus addition has tripped me up many times.

And the returnTagObject just does a getElementById I assume?

And what output do you mean? Are you trying to move a DIV and instead
it is creating another DIV?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top