您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

js同比例缩放图片的小例子_javascript技巧

2024/12/8 15:27:00发布16次查看
复制代码 代码如下:
function drawimage(imgd, fitwidth, fitheight) {
    var image = new image();
    image.src = imgd.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= fitwidth / fitheight) {
            if (image.width > fitwidth) {
                imgd.width = fitwidth;
                imgd.height = (image.height * fitwidth) / image.width;
            } else {
                imgd.width = image.width;
                imgd.height = image.height;
            }
        } else {
            if (image.height > fitheight) {
                imgd.height = fitheight;
                imgd.width = (image.width * fitheight) / image.height;
            } else {
                imgd.width = image.width;
                imgd.height = image.height;
            }
        }
    }
}
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product