$(document).ready(function(){
$('.photo li').waitForImages(function() { // Function which monitors whether the loaded image.
if($(this)){
$(this).show(); // if the picture is found, the element which is displayed with the picture.
}else{
$(this).remove(); // if not, remove the item.
}
});
});
.photo:nth-child(1) li:nth-child(1) {background: url("../img/cake.jpg") no-repeat;} - this picture is.
.photo:nth-child(2) li:nth-child(1) {background: url("../img/caked.jpg") no-repeat;} - this is not.
.photo:nth-child(3) li:nth-child(1) {background: url("../img/cakef.jpg") no-repeat;} - this is not.
.photo li {
display: inline-block;
border: 1px solid black;
width: 270px;
height: 200px;
}
<ul class="photo">
<p></li>
</ul>
<ul class="photo">
<p></li>
</ul>
<ul class="photo">
<p></li>
</ul>
$(document).ready(function() {
$('.photo li').waitForImages(function() {
$(this)[$(this).length ? 'show' : 'remove']();
});
});
but here we must see the function waitForImages to be sure that it will work. And while I'm gnawing doubt, because the method is not applied to the image, and the LI element. If inside the callback function this refers to it, it will always work show()$(function(){
$('.photo li').waitForImages({
each: function(loaded, count, success) {
$(this)[success ? 'show' : 'remove']();
},
waitForAll: true
});
});
Find more questions by tags jQueryJavaScript