Home  >  Article  >  Web Front-end  >  js image proportional scaling code_image special effects

js image proportional scaling code_image special effects

WBOY
WBOYOriginal
2016-05-16 18:27:211063browse
复制代码 代码如下:

var scaleImage = function(o, w, h){
var img = new Image();
img.src = o.src;
if(img.width >0 && img.height>0)
{
if(img.width/img.height >= w/h)
{
if(img.width > w)
{
o.width = w;
o.height = (img.height*w) / img.width;
}
else
{
o.width = img.width;
o.height = img.height;
}
o.alt = img.width "x" img.height;
}
else
{
if(img.height > h)
{
o.height = h;
o.width = (img.width * h) / img.height;
}
else
{
o.width = img.width;
o.height = img.height;
}
o.alt = img.width "x" img.height;
}
}
}

HTML
复制代码 代码如下:


pic






Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn