Hello. Please tell me how you need to change the script so that you can work with the "if that" condition for the following function:

- jQuery -

$(document).ready(function(){ $('.photo li').waitForImages(function() { // Ѐункция, которая слСдит, Π·Π°Π³Ρ€ΡƒΠ·ΠΈΠ»Π°ΡΡŒ Π»ΠΈ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ°. if($(this)){ $(this).show(); // Ссли ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π½Π°ΠΉΠ΄Π΅Π½Π°, ΠΏΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ элСмСнт с ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠΎΠΉ. }else{ $(this).remove(); // Ссли Π½Π΅Ρ‚, удаляСм элСмСнт. } }); }); 

- CSS -

 .photo:nth-child(1) li:nth-child(1) {background: url("../img/cake.jpg") no-repeat;} - такая ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΠ° Π΅ΡΡ‚ΡŒ. .photo:nth-child(2) li:nth-child(1) {background: url("../img/caked.jpg") no-repeat;} - Ρ‚Π°ΠΊΠΎΠΉ Π½Π΅Ρ‚. .photo:nth-child(3) li:nth-child(1) {background: url("../img/cakef.jpg") no-repeat;} - Ρ‚Π°ΠΊΠΎΠΉ Π½Π΅Ρ‚. .photo li { display: inline-block; border: 1px solid black; width: 270px; height: 200px; } 

- HTML -

 <ul class="photo"> <li></li> </ul> <ul class="photo"> <li></li> </ul> <ul class="photo"> <li></li> </ul> 

  • if something"? please make it clearer - Broouzer King
  • waitForImages () is from which library? - Sergey Omelchenko

2 answers 2

https://jsfiddle.net/95gz9sav/

 $(function(){ $('.photo li').waitForImages({ each: function(loaded, count, success) { $(this)[success ? 'show' : 'remove'](); }, waitForAll: true }); }); 

    The solution may be similar to this:
    A working example is http://jsbin.com/kikedeqeki/edit?html,output

     $(function(){ $('.photo > li').each(function(i, el) { var bgImg = new Image(); bgImg.src = getComputedStyle($(this).get(0)).backgroundImage.split('"')[1]; bgImg.onerror = function(){ $(el).remove(); }; }); }); 
    • $(this).get(0)===this - Grundy
    • @Grundy is already used to these $ (this), $ (this), $ (this) ... and indeed el could have been. - Jean-Claude