<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>圖網頁特效代碼</title>
<style>
<!-- ,很多情況下,不用這種方法,會增加ie負荷。-->
.thumbimage {
max-width: 50px;
max-height: 50px;
}
* html .thumbimage {
width: expression(this.width > 50 && this.width > this.height ? 50 : true);
height: expresion(this.height > 50 ? 50 : true);
}
</style>
</head>
<body>
<img src="/jscss/demoimg/wall3.jpg">
</body>
</html>
雅虎圖片的按比例縮小代碼::
<script type="text/網頁特效">
function setimgsize(img,width,height){
var maxwidth=width;//設定圖片寬度界限
var maxheight=height;//設定圖片高度界限
var heightwidth=img.offsetheight/img.offsetwidth;//設定高寬比
var widthheight=img.offsetwidth/img.offsetheight;//設定寬高比
if(img.offsetwidth>maxwidth){
img.width=maxwidth;
img.height=maxwidth*heightwidth;
}
if(img.offsetheight>maxheight){
img.height=maxheight;
img.width=maxheight*widthheight;
}
}
</script>
使用:<img src="/www.111cn.net/logo-yy.gif" border=0 onload="setimgsize(this,132,160);">
<script language="網頁特效">
<!--
var flag=false;
function drawimage(imgd){
var image=new image();
image.src=imgd.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 180/110){
if(image.width>180){
imgd.width=180;
imgd.height=(image.height*110)/image.width;
}else{
imgd.width=image.width;
imgd.height=image.height;
}
/*imgd.alt="bigpic" */
}
else{
if(image.height>110){
imgd.height=110;
imgd.width=(image.width*110)/image.height;
}else{
imgd.width=image.width;
imgd.height=image.height;
}
/*imgd.alt="bigpic" */
}
}
}
//-->
</script>
<img src="/www.111cn.net/logo-yy.gif" border=0 onload="drawimage(this);">
方法四(css強制)js代碼
<img src="..." alt="..." onload="resizeimage(this)" />
<script type="text/javascript">
function resizeimage(obj) {
obj.width = obj.width > 50 && obj.width > obj.height ? 50 : auto;
obj.height = obj.height > 50 ? 50 : auto;
}
</script>