2012-06-12 4 views
1

이 함수 또는 mousemove 이벤트를 파괴 할 수 있습니까?이 기능이나 mousemove 이벤트를 파괴 할 수 있습니까?

나는 두통을주고있는 jQuery에 몇 가지 코드가있다. 이 코드는 온라인상에서 mousemove 효과를 위해 요소 위에 지나갈 때 발견되었습니다. 그러나 그를 떠날 때 destuir이 어떻게 이벤트를 보충하거나 삭제할 수 있는지 알고 싶었습니다. 다음과 같이

내가 가지고있는 예는 다음과 같습니다

$("#icons").mouseenter(function(e) { 
    $(this).find('div').slidemouse(); 
}); 

$("#icons").mouseleave(function(e) { 
    $(this).find('div').slidemouse('destroy'); 
}); 

코드 플러그인 :

(function($) { 
    $.fn.slidemouse=function(options) { 
     var defaults= 
      { 
      height:'240px', 
      widthExpand:true, 
      mirror:false, 
      mirrorOpacity:.3 
     }; 
     var opts=$.extend(defaults,options); 
     var expands=1; 
     var galleryWidth=0; 
     var self=this; 
     self.css('overflow','hidden'); 
     self.children().css('height',opts.height); 
     self.children().children().each(function(index) { 
      galleryWidth=galleryWidth+$(this).outerWidth(true) 
     } 
     ); 
     if(opts.widthExpand) { 
      while(galleryWidth<self.width()) { 
       self.children().children(":nth-child("+expands+")").clone().appendTo(self.children()); 
       galleryWidth=galleryWidth+self.children().children(":nth-child("+expands+")").outerWidth(true); 
       expands++ 
      } 
     } 
     self.children().css("width",galleryWidth); 
     if(opts.mirror) { 
      self.clone().insertAfter(self).attr("id",""); 
      self.next().fadeTo(0,opts.mirrorOpacity) 
     } 
     if(opts.widthExpand||opts.mirror) { 
      $(window).bind("resize",resizeWindow) 
     } 
     function resizeWindow() { 
      if(opts.widthExpand) { 
       galleryWidth=0; 
       self.children().children().each(function(index) { 
        galleryWidth=galleryWidth+$(this).outerWidth(true) 
       }); 
       while(galleryWidth<self.width()) { 
        self.children().children(":nth-child("+expands+")").clone().appendTo(self.children()); 
        galleryWidth=galleryWidth+self.children().children(":nth-child("+expands+")").outerWidth(true); 
        expands++ 
       } 
       self.children().css("width",galleryWidth); 
       if(opts.mirror) { 
        self.next().remove(); 
        self.clone().insertAfter(self).attr("id",""); 
        self.next().fadeTo(0,opts.mirrorOpacity) 
       } 
      } 
     } 
     $(this).parent().mousemove(function(e) { 
      var x=e.pageX-this.offsetLeft; 
      var calc=(self.children().width()-self.width())/self.width(); 
      var left=x*calc; 
      var right=(self.width()-x)*calc; 
      self.stop().animate({scrollLeft: left}, 500); 
      if(opts.mirror) { 
       self.next().stop().animate({scrollLeft: right}, 500); 
      } 
     }) 
    } 
} 
)(jQuery); 
+2

I :

var defaults= { height:'240px', widthExpand:true, mirror:false, mirrorOpacity:.3, destroy: false }; var opts=$.extend(defaults,options); var self=this; if(destroy) { self.stop(); self.children().stop(); 

}

이제로하는 MouseLeave에 새로운 옵션을 사용할 수 있습니다 여기 처음 두 단락이 영어로는 의미가 없기를 두려워합니다. 문제를 조금 더 잘 설명하기 위해 질문을 수정 하시겠습니까? 아니면 단어를 다시 쓸 수 있도록 도와 줄 누군가를 얻으시겠습니까? 현재 문제가 무엇인지는 명확하지 않습니다. – halfer

+0

스페인어로하기 때문에 내 영어를 변명하면 –

답변

1

이 플러그인은 당신이 당신의 코드에서 필요로하는 특정 작업에 대한 방법이 없습니다. 이벤트를 바인드/바인드 해제하여 플러그인의 루틴이 실행되지 않도록 할 수 있습니다. 적절한 경우 $ (this) .unbind ('event')를 사용하십시오. 다른 방법으로, 당신은 그것에 파괴 플래그를 추가하여 플러그인의 코드를 수정을 시도 할 수 있습니다 :

$(this).slidemouse({destroy: true}); 
+0

나는 아이디어를 일하면서 코드를 실행하기 위해 약간 수정하고, 스페인어로하기 때문에 내 영어를 변명 할 수있다. if (opts.destroy) { \t opts.destroy (opts); \t self.stop(); \t self.children(). stop(); } –

관련 문제