• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

enlarging image with a constant speed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to provide delay in Javascript? I know about setTimeOut function. But what I mean is, enlarging a image slowly or something like that. Is there any easy way to do this? I am trying to do the same by setTimeOut function like this:



I think, it should work. But unknowingly alert(imgObj.height); returns undefined. Why I am not able to pass image object properly from one function to another?

Thanks.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you should be using

obj.style.height = yourVar + "px";

Eric
 
Rizwan Mohammad
Ranch Hand
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason, style also didn't work. It is not identifying image object as image object at all.
I declare variable globally to assign image object and avoid using the passing of image object to setTimeout function..
Here is the edited code snippet..
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is bad anyway:

for(var i=currHeight; i>=50; i = i-5) {setTimeout("setImageSize('"+i+"', '"+i+"')",5);}

You are doing a for loop, all of this 5 seconds will be fired at basically the same time if your code worked.

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way you want to code it would be something like this:



Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic