Alright, so generally I'm using document.create Element("IMG"). ... but, I've noticed something just recently that made me switch to "new Image()"
What I'm doing is creating a photo gallery of sorts, where i basically want to supply a total # of images, rows/cols max thumb/full image and let the script do the work. The solution I've opted for is to load the images once and change their size / position / visibility to show "thumb galleries" or "full image size" [and allow for pagination and all the bells & whistles]....
Naturally, the problem relates to the size of the images. When I first load a gallery, I load all the images off screen without height/width specified... I then use the onLoad event of the images to grab the "correct" height/width.
[code=javascript]
function Photo( ... ) {
...
this.element = document.create Element("IMG");
this.element.on load = callbackFunc( this, "init" );
...
}
/* callbackFunc is a function I use to let me use "this" inside an event handler
-- similar to prototype's "bindAsEventLis tener" for those familiar with it */
/* _event = Event object; _this = source element (loaded image) */
Photo.prototype .init = function( _event, _this ) {
this.width=_thi s.width;
this.height=_th is.height;
}
[/code]
I noticed the height/width of my image were being populated as 0. Only in Internet Explorer -- and intermittently. I think that may have something to do with cached images ... or something. So, I was racking my brain for literally HOURS over this stupid little thing.... and finally, I ended up switching to:
[code=javascript]this.element = new Image()[/code]
and now it works in both browsers.... all the time.
anyone else noticed this problem? I saw a post about it on some other forum, but there was no resolution to the problem.
What I'm doing is creating a photo gallery of sorts, where i basically want to supply a total # of images, rows/cols max thumb/full image and let the script do the work. The solution I've opted for is to load the images once and change their size / position / visibility to show "thumb galleries" or "full image size" [and allow for pagination and all the bells & whistles]....
Naturally, the problem relates to the size of the images. When I first load a gallery, I load all the images off screen without height/width specified... I then use the onLoad event of the images to grab the "correct" height/width.
[code=javascript]
function Photo( ... ) {
...
this.element = document.create Element("IMG");
this.element.on load = callbackFunc( this, "init" );
...
}
/* callbackFunc is a function I use to let me use "this" inside an event handler
-- similar to prototype's "bindAsEventLis tener" for those familiar with it */
/* _event = Event object; _this = source element (loaded image) */
Photo.prototype .init = function( _event, _this ) {
this.width=_thi s.width;
this.height=_th is.height;
}
[/code]
I noticed the height/width of my image were being populated as 0. Only in Internet Explorer -- and intermittently. I think that may have something to do with cached images ... or something. So, I was racking my brain for literally HOURS over this stupid little thing.... and finally, I ended up switching to:
[code=javascript]this.element = new Image()[/code]
and now it works in both browsers.... all the time.
anyone else noticed this problem? I saw a post about it on some other forum, but there was no resolution to the problem.
Comment