jQuery - 如何调用方法/原型函数

时间:2014-10-18 23:34:33

标签: javascript jquery sidebar

我使用粘性侧边栏使我的侧边栏粘住:http://github.com/caphun/jquery.stickysidebar/我还使用AJAX多次重新加载页面。一段时间后,滚动滞后,我认为这是因为每次重新加载内容而不破坏stickysidebar。

如何在此处调用销毁功能?

我试过

  

$(' .stickem&#39)。stickySidebar.destroy();

  

$(' .stickem&#39)。stickySidebar("破坏&#34);

但都没有奏效。这是原型:

  

$。stickySidebar.prototype = {

     

init:function(){

// code
     

},

     

粘性:功能(){

//code  
     

},

     

bind:function(){},

     

destroy:function(){
        警报(' H&#39);         this.element.unbind(" destroy",this.teardown);         this.teardown();
    },

     

teardown:function(){          的console.log(' EEE&#39);          $ .removeData(this.element [0],this.name);          this.element.removeClass(this.name);          this.unbind();          this.element = null;
    },

     

unbind:function(){}

     

}

1 个答案:

答案 0 :(得分:1)

这不是你如何做jQuery插件。如果您想将其称为$('.stickem').stickySidebar("destroy");(这是推荐的方式),请执行以下操作:

$.fn.stickySidebar = function(action) {
    if (action === 'destroy') {
        ...
    }
};

请参阅http://learn.jquery.com/plugins/basic-plugin-creation/