新闻内容页面自动调整超宽图片大小
2009-12-30 16:39 starlet 阅读(535) 评论(0) 编辑 收藏 举报function changeImgSize() {
var Article_Content_ID = "article_content"; //文章内容所在的Div的ID
var MAX_Width = 600; //最大图片宽度
var imgs = document.getElementById(Article_Content_ID).getElementsByTagName("img");
for ( var i = 0,len = imgs.length;i<len;i++ )
{
if( parseInt(imgs[i].width,10) > MAX_Width ){
var iw = parseInt(imgs[i].width,10) ;
var ih = parseInt(imgs[i].height,10) ;
imgs[i].style.width = MAX_Width +"px";
imgs[i].style.height = parseInt( ih * MAX_Width / iw ) + "px";
imgs[i].border='0';//由于添加连接后有边框,再此处设为0
imgs[i].setAttribute("onclick","javascript:window.open("+imgs[i].src+")");
//var outerHTML_temp = imgs[i].outerHTML; //获取img对象内容
//outerHTML_temp="<a href='"+imgs[i].src+"' target='_blank'>"+outerHTML_temp+"</a>"; //拼接href
//imgs[i].outerHTML = outerHTML_temp; //输出新的标签
}
}
}
var Article_Content_ID = "article_content"; //文章内容所在的Div的ID
var MAX_Width = 600; //最大图片宽度
var imgs = document.getElementById(Article_Content_ID).getElementsByTagName("img");
for ( var i = 0,len = imgs.length;i<len;i++ )
{
if( parseInt(imgs[i].width,10) > MAX_Width ){
var iw = parseInt(imgs[i].width,10) ;
var ih = parseInt(imgs[i].height,10) ;
imgs[i].style.width = MAX_Width +"px";
imgs[i].style.height = parseInt( ih * MAX_Width / iw ) + "px";
imgs[i].border='0';//由于添加连接后有边框,再此处设为0
imgs[i].setAttribute("onclick","javascript:window.open("+imgs[i].src+")");
//var outerHTML_temp = imgs[i].outerHTML; //获取img对象内容
//outerHTML_temp="<a href='"+imgs[i].src+"' target='_blank'>"+outerHTML_temp+"</a>"; //拼接href
//imgs[i].outerHTML = outerHTML_temp; //输出新的标签
}
}
}