javascript部分
//处理图片大小问题
$('.des-img img,.des-img2').each(function(index, ele) {$(ele).load(function() {//监听当前图片加载完成
if($(ele).hasClass('hasSet')) {
} else {
$(ele).addClass('hasSet');
var img = new Image();//创建图片
img.src = ele.src;//设置src
var height = img.height;//实际图片的高
var width = img.width;//实际图片的宽
var imgHeight = $(ele).height()//dom中设置的显示高度,这是是高度固定
if(width > height) {//当实际的宽大于高时,动态设置宽度
var setWidth = imgHeight * (width / height) + 'px'//宽高比
$(ele).width(setWidth);//设置dom中的宽度
}
}
})
})