[thelist] Help modify a JS

miinx lists at miinx.com.au
Mon Oct 21 22:05:00 CDT 2002


Le Sauvage wrote:
 > I have effected the changes you suggested, but it is not working
 > still. Please refer to the full html document below. Maybe I made a
 > boo boo somewhere?.

you're so close!  You've changed deltaX to be -1, (which is quite
logical), so we need to be *adding* that to the currentX value to get
the movement going backwards (adding a negative = subtraction)...
however I had previously changed the incrementing lines to be
subtracting deltaX instead... which means we've now got a double
negative (= a positive) so it's still gonna go forwards.  Either the
incrementing lines, or the deltaX value, need to be negative - but not both.

The other prob is that within the conditional you're testing if
"currentY <= end Y"... stick your initial values in there, and you'll
see we're checking if "500 <= 501" which is always true, so we're never
getting into the incrementing bit anyway, hence the div is not moving.
Needs to be "if currentY >= endY" instead.

Hope that makes sense and doesn't just confuse you more!  Here's the
script that works:

<SCRIPT  LANGUAGE="JavaScript1.2">
<!--

// Animation parameters
startX = 500;
startY = 500;
endX = 0;
endY = 501;
deltaX = -1;
deltaY = 0;
movePeriod = 50;

// Animation code
function movement() {
  if(currentY >= endY || currentX <= endX) {
   currentX = startX;
   currentY = startY;
   } else {
   currentX += deltaX;
   currentY += deltaY;
   }
  }

function setPosition(x,y) {
  divStyle.left = currentX;
  divStyle.top = currentY;
  }

function moveDiv() {
  movement();
  setPosition();
}

function moveImage() {
	if (document.getElementById)
  		divStyle = document.getElementById("mi").style;
	else if (document.all) {
	 	document.all = document;
	 	document.all.mi.style = document.all.mi;
		divStyle = document.all.mi.style;
	}
	 currentX = startX;
	 currentY = startY;
	 setPosition(currentX, currentY);
	 divStyle.visibility = "visible";
	 setInterval("moveDiv()",movePeriod);
  }

window.onload = moveImage;

//-->
</SCRIPT>


I should have just posted the whole thing first time... sorry for that.
  Hopefully I haven't just confused the hell outta you :)

Good luck!

Karen
-------
Miinx Design & Development
e :: karen at miinx.com.au
p :: 0413.880.302
w :: www.miinx.com.au





More information about the thelist mailing list