前面要加载一个jquery库。
调用
代码二:
$(window).bind("load", function() {
// 图片修改大小
$('#imglist img').each(function() {
var maxWidth = 120; //初始化最大显示宽度
var maxHeight = 120; //初始化最大显示高度
var ratio = 0;
var width = $(this).width();
var height = $(this).height();
if(width > maxWidth){
ratio = maxWidth / width;
$(this).css("width", maxWidth);
$(this).css("height", height * ratio);
height = height * ratio;
}
if(height > maxHeight){
ratio = maxHeight / height;
$(this).css("height", maxHeight);
$(this).css("width", width * ratio);
width = width * ratio;
}
});
});
代码三:
代码四: 推荐使用
$('#content').find('img').each(function(){
var img = this;
if (img.width > 600) {
img.style.width = "600px";
img.style.height = "auto";
//$(img).removeAttr('height');
var aTag = document.createElement('a');
aTag.href = img.src;
aTag.target="_blank";
$(aTag).addClass('bPic')
.insertAfter(img).append(img)
.lightBox(options);
}
});
这个content就是文章内容部分的id,方便控制制定位置的图片大小,推荐使用。










