Using JavaScript to automatically generate equal proportions of the sketch
Source: Internet
Author: User
JavaScript <!--
This example shows that proportional thumbnails are automatically displayed when the picture is loaded. When doing Web applications will often encounter customers upload a large picture, but when the display of the outline of the height and width than manually set, because the shape of the picture will cause the display deformation, here with a small script to solve this problem, You can modify it to make it more generic, such as adding an img parameter to the wa_setimgautosize () function, and then sending yourself to call the function in the picture's onload= event.
-->
<HTML>
<HEAD>
<TITLE> demo picture and so on scale shrink </TITLE>
<script>
function Wa_setimgautosize ()
{
var img=document.all.img1;//get Pictures
var maxwidth=200;//set Picture width limit
var maxheight=100;//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.readystate!= "complete") return false;//ensure that the picture is fully loaded
if (img.offsetwidth>maxwidth) {
Img.width=maxwidth;
Img.height=maxwidth*heightwidth;
}
if (img.offsetheight>maxheight) {
Img.height=maxheight;
Img.width=maxheight*widthheight;
}
}
</script>
</HEAD>
<BODY>
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.