1、$(window).load(function () {
$(".dynamics .all img").each(function (i, item) {
item = $(item);
if (item.width() > 630) {
item.addClass('xianimg');
}
else {
item.remove('xianimg');
}
});
$(".dynamics .all img").each(function (i, item) {
item = $(item);
if (item.width() > 630) {
item.addClass('xianimg');
}
else {
item.remove('xianimg');
}
});
});
为了兼容google $(window) 刷新才不会出现问题。
2、写在函数中的循环
$.each(minicontent_img, function (i, item){
item = $(item);
if (item.width() > 525)
{
item.css({ "width": "100%", "height": "100%" });
}
else
item.css({ "width": "auto", "height": "auto" });
});