Re: Positioning content with div tags - whats wrong here?
- From: David Mark <dmark.cinsoft@xxxxxxxxx>
- Date: Tue, 4 Dec 2007 09:03:44 -0800 (PST)
On Dec 4, 11:01 am, Randell_D <fiprojects....@xxxxxxxxx> wrote:
I got some javascript within Dreamweaver MX and am trying to
Oops. That's a bad place to get JavaScript.
understand it - I got it to work and even managed to make some changes
to make it fit my web app but I don't like to use something unless I
am comfortable supporting it. So I've begun to write my own and am
That's a good idea.
failing to get it to work...
In the code below, I would have expected the words "our crap" to be
located 400px down, 400px from the left but instead the words just
appear in top left corner regardless of the co-ordinates i use.
This is my version - I'd appreciate it if someone could direct me as
to what is missing...
After the <BODY> tag I have the following
<div id="ourID"></div>
<script language="javascript">
Get rid of that language attribute. Optionally, add type="text/
javascript".
function positionThis( content , tag, x, y )
{ ///////////////////////////////////////////////////////////////////////////-/////////////////////////////////////////////
// Setup the environment
// If we were not passed co-ordinates so prepare to create dynamic
values
if( arguments.length < 3 )
{ x=-1;
y=-1;
}
// We don't have a valid x co-ordinate so create one
if( x<0 )
{ x = Math.floor(screen.width/3); }
// We don't have a valid y co-ordinate so create one
if( x<0 )
I assume you mean y<0, but the whole thing is silly. Why set x and y
to -1 in the first place?
{ y = Math.floor(screen.height/5); }
// Reference the tag using a method valid for this browser
You can't reference a tag. Dreamweaver meant to say element.
var pointer=new Object();
There is no need to instantiate an Object here. Also, "pointer" is a
lousy name for a variable in any language (and particularly
inappropriate in JavaScript.)
if( document.all[tag] )
What if the "all" property does not exist? Change to:
if (document.all)
{ pointer=document.all[tag]; }
if( document.getElementById(tag) )
Same here and put an else before the if.
{ pointer=document.getElementById(tag); }
// Position the pointer
Check that "pointer" was set to an element with a style property
before proceeding any further.
if (pointer && pointer.style) {
pointer.left=x;
pointer.style.left = x + 'px';
pointer.top=y;
Same.
// Display our content
if( pointer.visibility )
{
pointer.visibility = "hidden";
pointer.document.write(content);
pointer.document.close();
pointer.visibility = "visible";
}
Delete that clause as you can't find an element in NN4 with
document.all or document.getElementById.
else
{
pointer.display = "none";
Delete.
pointer.innerHTML = content;
pointer.display = "block";
pointer.style.position = 'absolute';
The computed style will be now be 'block' and the element will be
positioned where you want it, assuming it doesn't have a positioned
parent.
}
return true;
Why return anything unconditionally?
}
}
positionThis( "our crap", "ourID", 400, 400 );
</script>
.
- Follow-Ups:
- Re: Positioning content with div tags - whats wrong here?
- From: Thomas 'PointedEars' Lahn
- Re: Positioning content with div tags - whats wrong here?
- References:
- Positioning content with div tags - whats wrong here?
- From: Randell_D
- Positioning content with div tags - whats wrong here?
- Prev by Date: please help me
- Next by Date: Re: please help me
- Previous by thread: Re: Positioning content with div tags - whats wrong here?
- Next by thread: Re: Positioning content with div tags - whats wrong here?
- Index(es):
Relevant Pages
|