jQuery Images fade in on load

Posted 3 years ago     5348      jquery image load

From Stackoverflow: http://stackoverflow.com/questions/9845774/fade-in-images-after-they-have-loaded

<div id="image"> <img id="preload" onload="fadeIn(this)" src="http://farm8.staticflickr.com/7227/7007769551_3b5b1640ea_b.jpg" style="display:none;" /> </div> <script> // this function must be defined in the global scope window.fadeIn = function(obj) { $(obj).fadeIn(1000); }‚Äč </script>


This is fine and all but it can be better handled in an unobtrusive way.

<img src="http://farm8.staticflickr.com/7227/7007769551_3b5b1640ea_b.jpg" class="animated"/> .animated { display: none; } $(function(){ $('img').not(':visible').fadeIn(1000); });

You need to be logged in to post comments.

Welcome to Snippet Repo!

Discover, share and save useful code snippets.

Join our community over over 2,000 members! Currently a 48% acceptance rate. Apply for membership →