Witam, męcze się z wyborem wszystkich img w danym li.
li mam 4 a w każdym po 3 obrazki.

chodzi o to aby po najechaniu na li wszystkie obrazki z tego właśnie li zmieniły się na kolorowe a po opuszczeniu znów były szare.
obecnie doszedłem do momentu gdzie tylko jeden się zapala i gaśnie i nie wiem w jaki sposób dokonać tego.
próbowałem z pseudoklasami :first itd. ale pojawia się drugi problem gdyż elementy li są losowe rozmieszczane.

poniżej źródła:

  1. <script type="text/javascript">
  2.  
  3. // $(".content img").css({"display":"none");
  4.  
  5. // On window load. This waits until images have loaded which is essential
  6. $(window).load(function(){
  7.  
  8. // Fade in images so there isn't a color "pop" document load and then on window load
  9. $(".content img").animate({opacity:1},500);
  10.  
  11. // clone image
  12. $('.content img').each(function(){
  13. var el = $(this);
  14. el.css({"position":"absolute"}).wrap("<div class='img_wrapper' style='display: inline-block'>").clone().addClass('img_grayscale').css({"position":"absolute","z-index":"998","opacity":"0"}).insertBefore(el).queue(function(){
  15. var el = $(this);
  16. el.parent().css({"width":this.width,"height":this.height});
  17. el.dequeue();
  18. });
  19. this.src = grayscale(this.src);
  20. });
  21.  
  22. // Fade image
  23. $('.content img').mouseover(function(){
  24. $(this).parent().find('img:first').stop().animate({opacity:1}, 10);
  25. })
  26. $('.img_grayscale').mouseout(function(){
  27. $(this).stop().animate({opacity:0}, 10);
  28. });
  29. });
  30.  
  31. // Grayscale w canvas method
  32. function grayscale(src){
  33. var canvas = document.createElement('canvas');
  34. var ctx = canvas.getContext('2d');
  35. var imgObj = new Image();
  36. imgObj.src = src;
  37. canvas.width = imgObj.width;
  38. canvas.height = imgObj.height;
  39. ctx.drawImage(imgObj, 0, 0);
  40. var imgPixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
  41. for(var y = 0; y < imgPixels.height; y++){
  42. for(var x = 0; x < imgPixels.width; x++){
  43. var i = (y * 4) * imgPixels.width + x * 4;
  44. var avg = (imgPixels.data[i] + imgPixels.data[i + 1] + imgPixels.data[i + 2]) / 3;
  45. imgPixels.data[i] = avg;
  46. imgPixels.data[i + 1] = avg;
  47. imgPixels.data[i + 2] = avg;
  48. }
  49. }
  50. ctx.putImageData(imgPixels, 0, 0, 0, 0, imgPixels.width, imgPixels.height);
  51. return canvas.toDataURL();
  52. }
  53.  
  54.  



i HTML

  1. <div class="content">
  2.  
  3.  
  4. <ul id="tabela_home">
  5. <li class="random1"><a href="../gmp-power/strona-glowna-gmp-power.html"><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/log-power.png" alt=""><br><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/fot4.png" alt=""><br></a>
  6. <h2>SYSTEMY ZARZĄDZANIA BUDYNKIEM</h2>
  7. <a href="../gmp-power/strona-glowna-gmp-power.html">Systemy zarządzania budynkiem BAS/BMS to systemy nadzoru i sterowania, integrujące różne podsystemy, urządzenia i sterowniki...<br><br><img src="../images/more1.png" alt=""></a></li>
  8. <li class="random2"><a href="../gmp-office/strona-glowna-gmp-office.html"><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/log-office.png" alt=""><br><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/fot1.png" alt=""><br></a>
  9. <h2>MATERIAŁY EKSPLOATACYJNE</h2>
  10. <a href="../gmp-office/strona-glowna-gmp-office.html">Systemy zarządzania budynkiem BAS/BMS to systemy nadzoru i sterowania, integrujące różne podsystemy, urządzenia i sterowniki...<br><br><img src="../images/more3.png" alt=""></a></li>
  11. <li class="random3"><a href="../gmp-light/strona-glowna-gmp-light.html"><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/log-light.png" alt=""><br><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/fot3.png" alt=""><br></a>
  12. <h2>PRODUKCJA</h2>
  13. <a href="../gmp-light/strona-glowna-gmp-light.html">Korzystając ze wsparcia&nbsp; największych fabryk w Europie, GMP light &nbsp;jest w stanie wyprodukować profesjonalne Oprawy i systemy oświetleniowe...&nbsp;<br><br><img src="../images/more2.png" alt=""></a></li>
  14. <li class="random1"><a href="../gmp-electro/strona-glowna-gmp-electro.html"><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/log-electro.png" alt=""><br><img style="display: block; margin-left: auto; margin-right: auto;" src="../images/fot2.png" alt=""><br></a>
  15. <h2>OKABLOWANIE STRUKTURALNE</h2>
  16. <a href="../gmp-electro/strona-glowna-gmp-electro.html">Tam, gdzie istnieje potrzeba, aby w wydajny, szybki i uniwersalny sposób dostarczyć użytkownikom różnego rodzaju usługi ... <br><br><img src="../images/more4.png" alt=""></a></li>
  17. </ul>
  18.  
  19. </div>