2013-03-11 103 views
1

我正在寫一個簡單的滑塊插件只是爲了學習一個小jQuery,也許用於我自己的項目。jquery插件添加公共方法

滑塊工作正常,但我想添加一些公共方法,如goToSlide(x),我不知道如何創建公共方法。

你有一個的jsfiddle here

我試圖像:

var slideto = function(position){ 
    gotoslide(position); 
}; 

現在,我使用這樣的插件:

$('#home-slider').pxslider({ 
    slideWidth: 300, 
    speed: 500, 
    onSlideBefore: function(){ 
       $('p.debug span').html('starting animation'); 
      }, 
    onSlideAfter: function(){ 
       $('p.debug span').html('stop animation'); 
      } 

    }); 

,我想這樣做somethig像:

$('#home-slider').pxslider().gotoslide(x); 
or 
$('#home-slider').pxslider('gotoslide','x'); 

jsfiddle帶有示例代碼here

+0

您是否找到任何解決方案?我也試圖實現像「$('#htmlid')。myplugin()。publicmethod(x);」。 – 2013-05-21 07:05:16

+0

是的,我已經重寫了代碼。看看它https://github.com/oterox/jquery.pxslider – Oterox 2013-05-21 10:07:49

回答