WEB开发网
开发学院网页设计JavaScript js实现图片大小等比缩放 阅读

js实现图片大小等比缩放

 2009-06-30 05:25:00 来源:WEB开发网   
核心提示:function resize(thumbs_size) { var max = thumbs_size.split('x'); var fixwidth = max[0]; var fixheight = max[1]; imgs = document.getElementsB
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 = "点击查看放大图片";  
     }  
   }  
}

Tags:js 实现 图片

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接