前面要加载一个jquery库。
<script type="text/javascript">
var setNewsImg = function(obj){
$(obj).find('img').each(function(i){
var imgw = $(this).width();
var imgh = $(this).height();
var scale=1;
if(imgw>634){
scale = 634/imgw;
console.log(scale);
$(this).height(scale*imgh);
$(this).width(scale*imgw);
}
});
}
</script type="text/javascripy">
调用
<script>
$(function(){
setNewsImg('.news-img')
})
</script>文章中所以的图片width大小设置
最新推荐文章于 2024-04-16 00:16:42 发布
本文介绍了一个使用jQuery实现的图片自适应调整方案。该方案能够确保图片宽度不超过指定的最大宽度(例如634像素),并相应地调整高度以保持原始宽高比。

6693

被折叠的 条评论
为什么被折叠?



