Forum Moderators: open
Error: divPath has no propertiesfrom line 5 and no movement and I can't figure out why it's not picking up the properties. Here's the code:
javascript:
function moveIt(id,x)
{var supported = (document.getElementById);
if (!supported) return;
var divPath = document.getElementById(id);
var currPos = parseInt(divPath.style.left);
if (currPos < x)
{currPos += 5;
divPath.style.left = currPos;
setTimeout("moveIt('" + id + "'," + x+ ")",10);
}
}
window.onload = moveIt('birdy',300);
#birdy {position: absolute; top: 275px; left: 34px; width: 265px; height: 248px; background: url(images/bird.png) no-repeat; }
<body id="splash">
<div id="wrap"><div id="content">
...
<div id="birdy"> </div></div></div>
</body>
Any help would be greatly appreciated.
Your problem is that the js function is attempting to get the style.left of the birdy div when you have not directly assigned a 'left' to the div. Rather you have applied a style to the birdy div. As far as js is concerned, there is no style.left assigned to the birdy div unless you explicitly assign one.
If you put style="left:34px" in the birdy div itself, your function should work fine.
Alternately, you can use the currentStyle attribute for IE and the getComputedStyle attribute for Moz.
Hope this helps,
ajkimoto
getElementById(id)I get "null".
I'm doing a little server-side scripting on the page (mainly to serve nn4) the output of the <head> ends up looking like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Home</title>
<meta name="Description" content="" />
<script type="text/javascript" src="bird.js"></script>
<link rel="stylesheet" href="birdy.css" type="text/css" media="all" />
<meta http-equiv="imagetoolbar" content="no" />
</head>
One day this bird is gonna fly.
window.onload = moveIt('birdy',300); That will assign window.onload to the value returned by the function - not what we want. It also calls the function immediately (not onload), before 'birdy' exists. Change it to:
window.onload = function(){ moveIt('birdy',300)};