2015-09-28 90 views
0

我有jQuery的功能是這樣的:。對()的.fn jQuery函數不工作

(function($){ 

    $.fn.LazyImageLoad = function() { 

     $(this).on('scroll load resize' , function() { 

      console.log ('Lazy Image Load run') 

      $('img' , this).each(function() { 
       $(this).hide(1000) ; 
      }); 

     }); 

    } 

})(jQuery); 

,並設置我的元素在這個溫控功能,例如

$(document).ready(function() { 

    $(window).LazyImageLoad(); 
    $('body').LazyImageLoad(); 
    $('.Container_C2').LazyImageLoad(); 

}); 

$(this).on().fn jquery function不行 和console.log$(img).show() for each img不運行,

那麼你會建議我做什麼?

+0

其中下面的代碼:'$(IMG).show()'。你是否錯過了一些代碼? – vijayP

+0

由於您綁定了某些未由某些元素處理的事件,因此請描述不起作用。而FYI,'this'已經是原型jq.fn方法中的jQuery對象 –

回答

1

您在consloe.log中有錯字錯誤。它應該是console.log

0

如果vijayP答案不工作,請嘗試:

(function($){ 

    $.fn.LazyImageLoad = function() { 

     $(this).on('scroll' , function() { 
      doMyStuff(this); 
     }); 
     $(this).on('load' , function() { 
      doMyStuff(this); 
     }); 
     $(this).on('resize' , function() { 
      doMyStuff(this); 
     }); 

    } 

    function doMyStuff(this) 
    { 
     console.log ('Lazy Image Load run') 

     $('img' , this).each(function() { 
      $(this).hide(1000) ; 
     }); 
    } 

})(jQuery);