2017-02-22 6 views
0

jqueryプラグインを2つ書き込んで表示すると、プラグインにUI値を渡す方法と使用方法がわかりませんでした。topIn()プラグインの中で。設定できないCustom jQuery Pluginの機能を使用する方法

基本的には、このプラグインは、あなたが$.fn.boxInViewtopIn関数を呼び出すことはありませんクライアント側

(function($) { 
    $.fn.boxInView = function(options) { 
    var settings = { 
     boxTopIn: null 
    }; 

    var options = $.extend(settings, options); 

    function topIn(elem) { 
     $(window).scroll(function() { 
     var screenBot = $(window).height(); 
     if (($(window).scrollTop() + screenBot) > elemTop) { 
      if ($.isFunction(options.onComplete)) { 
      options.onComplete.call(); 
      } 
      options.boxTopIn.call(); 
     } 
     }); 
    } 
    }; 
})(jQuery); 

$('#c').boxInView({ 
    boxTopIn: function() { 
    console.log('Box in View'); 
    } 
}); 

答えて

1

に再利用可能であるヌルコールバック関数boxTopInを作成することを意味しています。後topIn関数を定義し、この行を追加しよう:それが動作するはずですので

topIn(this); 

thisの値は、その点では、$('#c')になります。

関連する問題