The picture in the page exceeds the specified size, according to the original picture size reduction, not more than the same as the JS processing scheme

Source: Internet
Author: User
js| page

We often encounter images in a page that are displayed in our own size, which makes the page look more standardized.
For example, we want to display 130x160 pictures in the page, the equivalent of we put the picture into such a frame that, over the scale to the size of the box, small on the original display.
We have 2 different solutions here,
1, do not scale scaling <script language= "JavaScript" >
function Changeimg (mypic) {
var xw=130;
var xl=160;

var width = mypic.width;
var height = mypic.height;

if (Width > xw) mypic.width = XW;
if (Height > XL) mypic.height = XL;
}
</script>
2, Scaling by scaling
<script language= "JavaScript" >
function ChangeImg1 (mypic) {
var xw=160;
var xl=180;

var width = mypic.width;
var height = mypic.height;
var bili = width/height;

var a=xw/width;
var b=xl/height;

if (a>1| | B&GT;1)
{
if (a<b)
{
Mypic.width=xw;
Mypic.height=xw/bili;
}
if (a>b)
{
Mypic.width=xl*bili;
MYPIC.HEIGHT=XL;
}
}
}
</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.