JS Scale picture Size code

Source: Internet
Author: User

<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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.