0

I want the image to be displayed only after it's fully loaded. How can I do that?

<ul id="listcontainer">
    <li class="li1">
        <img src="images/m1.png">
    </li>
</ul>
Ash
  • 2,108
  • 2
  • 17
  • 22
Martinez
  • 149
  • 2
  • 12

3 Answers3

2

You could play with the document.ready and window.load events as window.load fires when all your images are loaded.

$(document).ready(function(){
    $("img").hide();
});

$(window).load(function(){
    $("img").show();
});
Lucas Rodrigues
  • 1,234
  • 2
  • 11
  • 22
0

You could try this Put this in your css #listcontainer{ opacity:0; }

    $(document).ready(function(){
    $('#listcontainer').animate({
    opacity: '1'
    },500);
});

If you really want to hide the images you could use .css and display:none; Put this in your css #listcontainer{ display:none; }

$(document).ready(function(){
        $('#listcontainer').css(
        'display', 'block'
        );
    });
Wim Pruiksma
  • 588
  • 5
  • 19
0

I think you can do something like this:

    <script>
        document.addEventListener('DOMContentLoaded', function(){
            var img = document.createElement("img");
            img.src = "images/m1.png";
            var src = document.getElementsByClassName("li1");
            src.appendChild(img);
        }, false);
    </script>
Ben
  • 209
  • 2
  • 8