Tuesday, April 5, 2011

A possible 'oops'y way to preload images

This presents a possibly new way of pre-loading images in javascript using the object oriented techniques. Check it out and let me know if this works for you.

<script type="text/javascript">
/**
* "parent class"
*/
function preloadImage( activeURL, inactiveURL ) {
this.active = new Image();
this.inactive = new Image();
this.v = [ activeURL, inactiveURL ];

this.assign = function() {
this.active.src = this.v[0];
this.inactive.src = this.v[1];
};
}

var images = new preloadImage( 'images/m1.jpg', 'images/m2.jpg' );
images.assign();
</script>



Here, the function "preloadImage" acts as a constructor for creating the pre-loaded functionality.
The variable "images" creates is an object of the above class, with the images to be pre-loaded as the variables.
The assign() function does the pre-loading job.

Did this work for you? Please let me know...

Wednesday, December 24, 2008

Pretty mundane stuff

Hi All,
I will be putting all the in-congruent stuff around me together and get them here. Hopefully, we will get to share a lot of things. Keep coming.