0

我有一個ie9問題,並不總是加載預加載的圖像。 有時我很想刷新頁面,然後它可以工作。jQuery預加載只適用於ie刷新

$jQuery.fn.img_preloader = function(options){ 
    var defaults = { 
     repeatedCheck: 550, 
     fadeInSpeed: 1100, 
     delay: 200, 
     callback: '' 
    }; 
    var options = jQuery.extend(defaults, options); 
    return this.each(function(){ 
     var imageContainer = jQuery(this), 
      images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}), 
      imagesToLoad = images.length;    
      imageContainer.operations = { 
       preload: function(){  
        var stopPreloading = true; 
        images.each(function(i, event){ 
         var image = jQuery(this); 

         if(event.complete == true){ 
          imageContainer.operations.showImage(image); 
         }else{ 
          image.bind('error load',{currentImage: image}, imageContainer.operations.showImage); 
         } 

        }); 
        return this; 
       },showImage: function(image){ 
        imagesToLoad --; 
        if(image.data.currentImage != undefined) { image = image.data.currentImage;} 

        if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed); 

        if(imagesToLoad == 0){ 
         if(options.delay > 0){ 
          images.each(function(i, event){ 
           var image = jQuery(this); 
           setTimeout(function(){ 
            image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed); 
           }, 
           options.delay*(i+1)); 
          }); 

          if(options.callback != ''){ 
           setTimeout(options.callback, options.delay*images.length); 
          } 
         }else if(options.callback != ''){ 
          (options.callback)(); 
         } 
        } 
       } 
      }; 
      imageContainer.operations.preload(); 
     }); 
    } 

回答

2

嘗試評論event.complete驗證並直接進入showImage事件。這不是最好的解決方案,但爲我工作。

$jQuery.fn.img_preloader = function(options) 
{ 
    var defaults = { 
    repeatedCheck: 550, 
    fadeInSpeed: 1100, 
    delay: 200, 
    callback: '' 
    }; 
    var options = jQuery.extend(defaults, options); 
    return this.each(function() 
    { 
    var imageContainer = jQuery(this), 
     images = imageContainer.find('img').css({opacity:0, visibility:'hidden'}), 
     imagesToLoad = images.length;    
     imageContainer.operations = { 
      preload: function(){  
       var stopPreloading = true; 
       images.each(function(i, event){ 
        var image = jQuery(this); 

        imageContainer.operations.showImage(image); 
        /*if(event.complete == true){ 
         imageContainer.operations.showImage(image); 
        }else{ 
         image.bind('error load',{currentImage: image}, imageContainer.operations.showImage); 
        }*/ 

       }); 
       return this; 
      },showImage: function(image){ 
       imagesToLoad --; 
       if(image.data.currentImage != undefined) { image = image.data.currentImage;} 

       if (options.delay <= 0) image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed); 

       if(imagesToLoad == 0){ 
        if(options.delay > 0){ 
         images.each(function(i, event){ 
          var image = jQuery(this); 
          setTimeout(function(){ 
           image.css('visibility','visible').animate({opacity:1}, options.fadeInSpeed); 
          }, 
          options.delay*(i+1)); 
         }); 

         if(options.callback != ''){ 
          setTimeout(options.callback, options.delay*images.length); 
         } 
        }else if(options.callback != ''){ 
         (options.callback)(); 
        } 
       } 
      } 
     }; 
     imageContainer.operations.preload(); 
    }); 
} 
0

替換此showimage功能..

showImage: function (g) { 
    d--; 

    if (g.data.currentImage != undefined) { 
     g = g.data.currentImage;      

    } 

    if (b.delay <= 0) { 
     g.css("visibility", "visible").animate({ 
      opacity: 1 
     }, b.fadeInSpeed); 

    } 
    if (d != 0) { 
     if (b.delay != 0) { 
      e.each(function (k, j) { 
       var h = a(this); 
       setTimeout(function() { 
        h.css("visibility", "visible").animate({ 
        opacity: 1 
        }, b.fadeInSpeed) 
       }, b.delay * (k + 1)) 
      }); 
      if (b.callback != "") { 
       setTimeout(b.callback, b.delay * e.length) 
      } 
     } else { 
      if (b.callback != "") { 
       b.callback() 
      } 
     } 
    } 
} 
相關問題