<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<TITLE>JS scale picture Size code </title>
<script language= "JavaScript Tutorial" >
function Downimage (IMGD) {
var image=new image ();
IMAGE.SRC=IMGD.SRC;
if (image.width>0 && image.height>0) {
if (image.width>=200) {
imgd.width=200;
imgd.height= (image.height*200)/image.width;
}else{
Imgd.width=image.width;
Imgd.height=image.height;
}
}
}
</script>
<body>
</body>
Method Two
JS Control Picture Scaling
<script language= "JavaScript Tutorial" >
<!--
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>
The picture can be written as it is used
Program code
Other methods
Use CSS tutorial +js to make pictures automatically scale-image not distorted
. thumbimage {max-width:100px;max-height:100px}/* for Firefox & IE7 * *
* HTML. Thumbimage {/* for IE6 * *
Width:expression (This.width > && this.width > This.height 100:auto);
Height:expression (This.height > 100:auto);
First line: FF and IE7 support
The second line: IE6 must add JS to be able to use
Test pass!
Method One:
In the picture attributes Riga style= ' width:expression (width>450?450:width); '
Highly style= ' height:expression (height>450?450:height); '
Method Two:
In the picture properties Riga onload= "if (this.width>550) this.width=550"
Code
<script language= "JavaScript" >
var imgobj;
for (i = 0; i < document.all.length; i++)
{
if (document.all (i). Tagname.tolowercase () = = "img")
{
Imgobj = document.all (i)//recommended only to determine the height or width of one, which can be automatically scaled
if (imgobj.height>500)//judge the height of the picture, if greater than 500, then set to 500, the value can be modified
{
imgobj.height=500
}
if (imgobj.width>700)//To determine the width of the picture, if greater than 700, then set to 700, the value can be modified
{
imgobj.width=700
}
}
}
</script>