Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

resizing image while page loads 1

Status
Not open for further replies.

gormster

Technical User
Mar 1, 2005
27
AU
is it possible to get an image to resize if it exceeds certain size limits without having to press a button? the problem as i see it is that since it takes time to load an image, if the script is run as the page loads, the image.width and image.height are undefined, meaning that I can't see if they are out of the boundaries and also I can't resize them in proprtion. this it the script i've got which doesn't work:
Code:
function imgsizer{
	var imgs = document.images;
	var imgHeight = imgs[0].Height;
	var imgWidth = imgs[0].Width;
	var scale;
	if (imgWidth > 800){
		scale = 800 / imgWidth;
		imgs[0].Height = imgHeight * scale;
		imgs[0].width = 800;
	} 
	if (imgs[0].Height > 600){
		scale = 600 / imgHeight;
		imgs[0].width = imgWidth * scale;
		imgs[0].height = 600;
	}
}

i've tried putting this function both in the body onLoad and in the <body></body> tags (without the function {} of course) but none of it seems to work.

is there some way that I can get it to be called after the image loads?
 
I'm not talking about CSS validation - I just said, quite clearly - after you asked for clarification - that I was talking about HTML vaslidation, so I'm not entirely sure why you posted a link to a CSS validator.

Incidentally, you might want to take a look at some of the tags on your page:


Dan



[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]
 
Dan I don't think you need height and width attributes for images for this type of doc type. The only attribute that is needed is alt for validation. Although I almost always use them for quicker page loading and so things don't "jump around" when the page loads.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

Glen
 

Glen,

You are both quite right - I have no idea why I thought that you needed a width and height attribute for validation... I thought I seem to remember having that issue before, although clearly I'm quite mistaken.

Dan


[tt]D'ya think I got where I am today because I dress like Peter Pan here?[/tt]
[banghead]

 
man, i thought i followed this up.

theEclipse was right, it was just capitalization problems. don't you hate when it's something tiny like that?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top