View Full Version : setInterval problem - what's wrong here?

10-31-2006, 12:37 PM
Hi all,

I'm trying to use setInterval to make a movement effect for a div. Here's the code:

onload=function() {
nowIDheight=nowIDheight.substr(0, nowIDheight.length-2); //to remove px
for (i=0; i<=100; i++)
setInterval(function(){document.getElementById("t").style.height=i+"px"}, 1000);
<div style="height: 100px;border: 1px solid red" id="t">bla</div>
But that doesn't do the trick.
What's wrong here?

10-31-2006, 09:58 PM
New question, sorry for the mess.

11-02-2006, 07:23 AM
what you need is to put the logic the for loop provides you inside the interval like so:

var nowID = document.getElementById("t");
var nowIDheight=nowID.style.height;
var nowIDheight=nowIDheight.substr(0, nowIDheight.length-2); //to remove px
var maxNowIDheight = nowIDheight+100;
function moveNowID()
nowID.style.height = (++nowIDheight)+"px";
if (nowIDheight == maxNowIDheight)
var moveInterval = setInterval(moveNowID, 1000);

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum