Click to See Complete Forum and Search --> : Help Me!!!!!!!!!!!!!!!!!!!!!!


elwell
08-05-2003, 09:11 PM
I need to fix this it is so annoying. I have been working on it for a little bit now. I want to make a pic move then stop at a certain point. I know this is DHTML but no one is at the DHTML forum right now. Heres WHAT i have currently:

<html><head><title>Dow Jon&reg</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide
function slide() {
document.all.mover.style.pixelLeft+= 10
if (document.all.mover.style.pixelLeft < document.all.rightfore.style.pixelLeft) {
setTimeout("slide()" ,10)
}
}
// End -->
</script>
<style type="text/css">
<!--
#mover {position: absolute; top:220px; left:-200px; z-index:30}
#rightfore {position: absolute; top:200px; left:260px; z-index:20}
//nj injin-->
</style>
</head>
<body OnLoad="slide()">
<span style="position: absolute; top:100px; left:233px; font-family: Trebuchet MS, sans-serif; color:black; font-size: 72; z-index:30">Dow Jon</span>
<div id="rightfore">
<img src="blackcircle.gif" />
</div>
<div id="mover">
<img src="blankcircle.gif" />
</div>
</body>
</html>

Exuro
08-05-2003, 10:31 PM
The problem in your code was that document.all.rightfore.style.pixelLeft is actually equal to zero. Javascript isn't able to get the left position of the object from the CSS definition, so it just says that the spot it starts at is 0. After knowing that, all you need to do is change your condition a little bit...


function slide() {
&nbsp;&nbsp;document.getElementById('mover').style.pixelLeft += 10
&nbsp;&nbsp;if (document.getElementById('mover').style.pixelLeft < 260) {
&nbsp;&nbsp;&nbsp;&nbsp;setTimeout("slide()" ,10)
&nbsp;&nbsp;}
}


Oh, and I changed the all.movers to getElementById('mover')s because it's more cross-browser compatable... Actually, it's just habbit, but still :-p. Anyway, hope that helps!

elwell
08-06-2003, 10:57 AM
Thank you soooooo much. It worked first try I didn't eveen have to change anything.

pyro
08-06-2003, 11:02 AM
Originally posted by Exuro
...getElementById('mover')s because it's more cross-browser compatable... Actually, it's just habbit, but stillIt's also the valid DOM way of doing it (http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-html.html#method-getElementById) instead of using proprietary methods (document.all or document.layers)