for just height
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<style type="text/css">
/*<![CDATA[*/
.resize{
height:400px;
}
.resize IMG{
height:100%;
}
/*]]>*/
</style></head>
<body>
<img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" />
<div class="resize" >
<img src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" />
</div>
</body>
</html>
for width and height
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/
var TO;
var maxmSec=1000; // maximum load time in milliseconds
function Resize(url,w,h,id){
clearTimeout(TO);
var img=new Image();
img.src=url+'?'+Math.random();
CkLoad(img,w,h,id,new Date());
}
function CkLoad(img,w,h,id,date){
if (new Date()-date<maxmSec){
if (img.complete&&img.width>50){
var r=img.width/img.height;
if (img.width>w){
img.width=w;
img.height=w/r;
}
if (img.height>h){
img.height=h;
img.width=h*r;
}
var obj=document.getElementById(id);
obj.style.width=img.width+'px'
obj.style.height=img.height+'px'
obj.src=img.src;
}
else {
TO=setTimeout(function(){ CkLoad(img,w,h,id,date); },100);
}
}
else {
alert('unable to load');
}
}
/*]]>*/
</script>
</head>
<body>
<input type="button" name="" value="Load" onclick="Resize('http://www.vicsjavascripts.org.uk/StdImages/Three.gif',160,40,'tst');"/>
<img id="tst" src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" />
</body>
</html>
Bookmarks