View Full Version : how to use js to adject pic sizes dynamicly after loading.?

02-15-2006, 02:12 AM
i have some pictures in a page. there are have difference sizes. some
of them are too widen for be arrange in a line. so
i been tried to adject their sizes to more suitable.

i add a event to that image likes:
<img id="img" onLoad="adjustSize(this)" src="123.jpg">

and write a function in javascript:
function adjustSize(obj){
if (obj.width>250){
if (obj.hight>268)


but exactly,i can get the image's width and height. cuz the loading
hasn't finished while the function of adjustSize works.

In addition,those picture were loaded from a database.
so first i can't exactly get the sizse when a bigger picture is
thus in the event of picture loading the function isn't works cuz it
keeping a wrong sizes as zero.
but the event 'onMouseOver' works well.cuz it cant get the size exactly
after they were completely loaded

can anyone tell me how to deal this?
Tks advanced.

02-15-2006, 10:26 AM
have u tried using offsetHeight and offsetWidth attributes of the image

02-16-2006, 12:29 AM
You could try using CSS to resize your pics. Although they all may have to be sized to the same dimension. Take a look at the end of this page...