Picture scaled (CSS mandatory) JS code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags ajax code content css tutorial force function html http

This article provides three kinds of pictures to shrink the code proportionally, one is to use the CSS tutorial to force the picture scaling down, after two is to use the Web page effects on the picture proportionally to shrink the code

<html xmlns= "http://www.jzread.com/1999/xhtml" >
<head>
<meta http-equiv= "Content-type" content= "HTML; charset=gb2312 "/>
<title> image Scaling (CSS mandatory) page special effects code </title>

<style>
<!--CSS to force a proportional reduction of the picture, in many cases, without this method, will increase the IE load. -->
. thumbimage {
max-width:50px;
max-height:50px;
}
* HTML. Thumbimage {
Width:expression (This.width > && this.width > This.height 50:true);
Height:expresion (This.height > 50:true);
}

</style>

</head>

<body>
<img src= "/jscss/demoimg/wall3.jpg" >
</body>
</html>


Yahoo picture's scaled down code::


<script type= "text/web Effects" >
function Setimgsize (img,width,height) {
var maxwidth=width;//set Picture width limit
var maxheight=height;//set Picture height limit
var heightwidth=img.offsetheight/img.offsetwidth;//set aspect ratio
var widthheight=img.offsetwidth/img.offsetheight;//set ratio of width to height
if (img.offsetwidth>maxwidth) {
Img.width=maxwidth;
Img.height=maxwidth*heightwidth;
}
if (img.offsetheight>maxheight) {
Img.height=maxheight;
Img.width=maxheight*widthheight;
}
}

</script>


Uses: <img src= "/www.jzread.com/logo-yy.gif" border=0  onload= "setimgsize (this,132,160);"
<script language= "Web Effects" >
<!--
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= "http://www.jzread.com/skin/default/imga/logo.gif" border=0 onload= "DrawImage" (this); >
Method four pictures scaled (CSS mandatory) JS code

<img src= "..." alt= "onload=" resizeimage (this)/>
<script type= "Text/javascript" >
function Resizeimage (obj) {
Obj.width = obj.width > && obj.width > Obj.height? 50:auto;
Obj.height = obj.height > 50? 50:auto;
}
</script>

Related Article

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.