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