[javascript]自动将大图片的宽度限定在一定范围

//将某个HTML元素内含的所有图片宽度限定在600以内

var imgMaxWidth=600;

function ImgLoad(obj) 

{

    for(var i=0;i<obj.all.tags("img").length;i++){

        var o=obj.all.tags("img")[i];

        if (o.width>imgMaxWidth){

            o.width=imgMaxWidth;

            o.removeAttribute("height");

            o.style.cursor="hand";

          }

    }

}

//然后在obj onload时调用这个函数即可

//还有一个函数,让用户用滚轮调整大小。

function bbimg(o){

        var zoom=parseInt(o.style.zoom, 10)||100;zoom+=event.wheelDelta/12;if (zoom>0) o.style.zoom=zoom+’%’;

   

}

//调用方法: onmousewheel="return bbimg(img)"

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.