小さすぎる画像を削除するための次のスクリプトがありますが、正しく機能しません。最初にページをロードすると、すべての画像が に置き換えられno-image.png
ます。ページを更新した後、正しく機能します。何が欠けていますか?
$(document).ready(function () {
$('.story-img').error(function () {
$(this).attr("src", "/Images/no-image.png");
$(this).css('border', 'none');
});
$(".story-img").each(function () {
var theImage = new Image();
theImage.src = $(this).attr("src") || $(this).src;
var imageWidth = theImage.width;
var imageHeight = theImage.height;
if (imageWidth < 32 || imageHeight < 32 || $(this).height() < 32 || $(this).width < 32) {
$(this).attr("src", "/Images/no-image.png");
$(this).css('border', 'none');
}
});
});