我想知道当我的屏幕分辨率低于980px时,是否有某种方法可以删除图像的宽度和高度?通过jquery或什么?
像这样的图像:
<img width="477" height="299" src="/uploads/2012/01/415.jpg" class="attachment-portfolio2 wp-post-image"/>
谢谢
答案 0 :(得分:2)
您可以使用以下CSS:
/* for all screens in general */
.wp-post-image {
width: 477px;
height: 299px;
}
/* specifically for screens smaller than (or equal to) 980px */
/* make sure this comes *after* the general rule */
@media (max-width: 980px) {
.wp-post-image {
width: auto;
height: auto;
}
}
答案 1 :(得分:1)
您可以使用jQuery removeAttr()
方法:
var images;
$(function() {
images = $('img.wp-post-image');
removeSize();
});
$(window).resize(removeResize);
function removeSize()
{
if($(window).width() < 980 && images.length > 0)
{
images.removeAttr('width').removeAttr('height');
}
}