2012-07-24 2 views
0

여기가 방향에 따라이 이름 공간을 사용하여 jQuery를 플러그인을 구축하기 위해 노력하고있어 메서드,jQuery를 이름 간격과의 setTimeout

var jScrollerMethods = { 
    ready:function(){ 
     return this.each(function(){ 
     var self = this, 
    $this = $(this), 
     data = $this.data('jScroller'); 

     settings.timeoutHandle = setTimeout(function(){ 
      if(settings.direction = "left"){ 
       this.moveLeft(); 
      }else if(settings.direction = "right"){ 
       this.moveRight(); 
      } 
     }, settings.time); 

     $this.data('jScroller', { 
      settings: settings, 
      element: this 
     }); 
    }); 
} 
$.fn.jScroller = function(call){ 
    if (jScrollerMethods[call]) { 
     return jScrollerMethods[call].apply(this, Array.prototype.slice.call(arguments, 1)); 
    } else if (typeof call === 'object' || ! call) { 
     if (call) { $.extend(settings, call); } 
     return jScrollerMethods.init.apply(this, call); 
    } else { 
     $.error('Method ' + call + ' does not exist on jQuery.jScroller'); 
    } 
} 

하지만 그래도에서는 setTimeout 일이 일어날 등의 창없는 플러그인 객체에서 해고되고 난 플러그인 번 페이지 당보다 더에 사용할 수 원하는 것을있는 것은 그래서 난 그냥 저장할 수 없습니다 창에 현재 개체가 어떻게 이것을 달성 할 수 있습니까?

+0

return this.eachthis 외부를 사용할 때하는 당신에게 정확한 선택을 결과를 줄 것이다 발견' this.moveLeft();'? 'self' (또는'$ this')를 사용하십시오. –

+0

고마워요.하지만 지금 알아 냈습니다. – HotHeadMartin

+0

그런 다음 다른 사람에게 익숙하다고 생각하거나 질문을 삭제할 경우 답을 해결책으로 제공해주십시오. –

답변

0

나는 당신이 문제가 있다고 생각

그래서 몇 가지 작업으로 내가 그것을 관리해야

,

var jScrollerMethods = { 
    ready:function(){ 
     selector = this; 

     return this.each(function(){ 
     var self = this, 
    $this = $(this), 
     data = $this.data('jScroller'); 

     settings.timeoutHandle = setTimeout(function(){ 
      if(settings.direction = "left"){ 
       selector.jScroller("moveLeft"); 
      }else if(settings.direction = "right"){ 
       selector.jScroller("moveRight"); 
      } 
     }, settings.time); 

     $this.data('jScroller', { 
      settings: settings, 
      element: this 
     }); 
    }); 
} 
$.fn.jScroller = function(call){ 
    if (jScrollerMethods[call]) { 
     return jScrollerMethods[call].apply(this, Array.prototype.slice.call(arguments, 1)); 
    } else if (typeof call === 'object' || ! call) { 
     if (call) { $.extend(settings, call); } 
     return jScrollerMethods.init.apply(this, call); 
    } else { 
     $.error('Method ' + call + ' does not exist on jQuery.jScroller'); 
    } 
}