Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 1.05 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. jQuery error() function not working in IE
  2. <style type="text/css">
  3. DIV#loader {
  4.     width: 500px;
  5.     height: 500px;
  6.     overflow: hidden;
  7. }
  8.  
  9. DIV#loader.loading {
  10.     background: url(spinner.gif) no-repeat center center;
  11. }
  12. </style>
  13.  
  14.  
  15. <script type="text/javascript">
  16. $(document).ready(function() {
  17.     var image_names = new Array(2);
  18.     image_names[0] = 'a.jpg';
  19.     image_names[1] = 'b.jpg';
  20.     var divs = document.getElementsByTagName("div");
  21.     for ( var i = 0; i < divs.length; i++) {
  22.         showImage(image_names[i], divs[i]);
  23.     }
  24. });
  25.  
  26. function showImage(src, div) {
  27.     var img = new Image();
  28.     $(img).load(function() {
  29.         $(this).hide();
  30.         $(div).removeClass('loading').append(this);
  31.         $(this).fadeIn();
  32.     }).error(function() {
  33.         setTimeout(function() {
  34.             $(img).attr('src', src);
  35.         }, 2000);
  36.     }).attr('src', src);
  37. }
  38. </script>
  39.        
  40. <body>
  41. <h1>Image Loading</h1>
  42. <div id="loader" class="loading"></div>
  43. <div id="loader" class="loading"></div>
  44. </body>
  45.        
  46. $(img).attr('src', src + "?" + (new Date().getTime()));