0

I've been trying to figure out for hours on how to make JQuery's .load() work. Here is the full code - it is an external JS file:

$(document).ready(function() {
  $(".loader a").hide();
  $(".loader a").find("img").on("load", function() {
    $(this).closest(".loader a").fadeIn("normal");
  });
);

$(".loader a").hide(); works but the rest don't - the images don't show up and they still remain hidden. It is unlikely the cause but do you think it has something to do with the PHP-JSON code? I don't know. Hope you guys can help. Cheers!

<?php
  $str_data = file_get_contents("portfolio/portfolio.json");
  $json = json_decode($str_data, true);
  shuffle($json['portfolio']);

  foreach ($json['portfolio'] as $portfolio) {
    echo "<div class='col-lg-3 col-md-4 col-xs-12 thumbnail portfolio-thumb'>";
      echo "<div class='portfolio-thumb-img'>";
        echo "<div class=\"loader\"><a href=\"", $portfolio["url"], "\"><img src=\"", $portfolio["main_image_url"], "\"></a></div>";
        echo "<h3>", $portfolio["title"], "</h3>";
        echo "<p>", $portfolio["category"], "</p>";
      echo '</div>';
    echo '</div>';
  }
?>

That above code is a PHP include file and it is going to be merged with the header.php and footer.php.

Myess
  • 1
  • [http://stackoverflow.com/questions/3877027/jquery-callback-on-image-load-even-when-the-image-is-cached][1] [1]: http://stackoverflow.com/questions/3877027/jquery-callback-on-image-load-even-when-the-image-is-cached This may help you... – Devasish Sep 20 '14 at 13:24
  • Thanks. I just tried that but the fadeIn animation is quite dodgy or not smooth. Will work on that example - find a way to make the animation smooth. Again thanks! – Myess Sep 21 '14 at 03:15

0 Answers0