当前位置导航:炫浪网>>网络学院>>网页制作>>JavaScript教程

js实现图片大小等比缩放

function resize(thumbs_size) {   
    var max = thumbs_size.split('x');   
    var fixwidth = max[0];   
    var fixheight = max[1];   
    imgs = document.getElementsByTagName('img');   
    for(i=0;i<imgs.length;i++) {   
        w=imgs[i].width;h=imgs[i].height;   
        if(w>fixwidth) { imgs[i].width=fixwidth;imgs[i].height=h/(w/fixwidth);}   
        if(h>fixheight) { imgs[i].height=fixheight;imgs[i].width=w/(h/fixheight);}         
        imgs[i].style.cursor= "pointer";   
        imgs[i].onclick = function() { window.open(this.src);}   
        if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) {   
            imgs[i].title = "点击查看放大图片";   
            imgs[i].onmousewheel = function img_zoom() {   
                var zoom = parseInt(this.style.zoom, 10) || 100;   
                zoom += event.wheelDelta / 12;   
                if (zoom> 0) {   
                    this.style.zoom = zoom + "%";   
                    return false;   
                }   
            }   
        }   
        else {   
            imgs[i].title = "点击查看放大图片";   
        }   
    }   
}
相关内容
赞助商链接