I'm using setTimeout() to animate an image moving across the screen to the edge of the page. When I call setTimeout() and pass it a this.function as the function to execute it won't do it & throws and err saying it's not a function. I've also tried passing a reference to an object and it didn't seem to like that either.
I've extended the Image class adding several prototype methods and proerties of my own. I wanted to call the Image instance's animateLeft method repeatedly & delayed so that it looks as though the image moves across the screen to the edge.
the _P functions are used to extend the Image object and they become the instance methods sans '_p' : animateLeft_p() can then be called using "this.animateLeft()"
Here's the code:
Here's the HTML code:PHP Code:
// Params that control the speed images animate left and up
var moveIncr = 1;
var timeInt = 10;
//instance method of Image to animate the image to the left edge of screen
this.lcounter = 1;
this.startX = this.getLeft();
this.movedSum = 0;
while(this.startX - this.movedSum > 0)
this.movedSum = this.movedSum + moveIncr;
///************Below is the problem call *************
this.style.left=parseInt(this.style.left) - pxls;
//add the methods & properties to each subsequent image object created
// so I can call using someImage.animateLeft() for example
Image.prototype.animateLeft = animateLeft_p;
Image.prototype.moveLeft = moveLeft_p;
Image.prototype.getLeft = getLeft_p;
Image.prototype.lcounter = 1;
Image.prototype.movedSum = 0;
Image.prototype.startX = null;
//Now create the image objects
projects = new Image(100,100);
projects.src = "http://www.bytality.com/prog_arch/images/projects_100x100.jpg";
I had been using public vars to do this, and that worked for a single image, but when I move multiple images at once, they share the control variables and don't move the entire distance correctly.PHP Code:
<IMG src="images/blue_logo_100x100.jpg" style="position:absolute;left:100;top:0;" height="100" id="bluelogo" width="100" onclick="this.animateLeft();">
Anyone know how I can make the code work using setTimeout() function or another function?