2013-04-18 3 views
1

상자에 대해 .off를 사용하여 이벤트 처리기를 제거 할 수 없습니다..off를 사용하여 이벤트 처리기 제거

상자를 클릭하면 해당 상자에서 제거 된 이벤트 처리기가 필요합니다. 현재 ".clickable"후크를 만들고 클래스를 제거하고 이벤트 처리기를 제거한 다음 모든 상자에 이벤트 처리기를 다시 적용하려고했습니다. ".box"클래스. 여러분의 조언과 도움을

 $('.clickable').off('click','**').on("click", function(event){ 

     if(!$('.box').is(':animated')) { 

      var position = $(this).position() 
      , targetPosition = $('.target').position(); 

      $(this) 
       .clone() //clone element 
       .addClass('cloned') //add class to cloned element 
       .css({ 
        'position' : 'absolute' 
       , 'top' : position.top 
       , 'left' : position.left 
       }) 
       .appendTo('body'); //append to the document 

       animate(position,targetPosition); 

       $(this) 
        .removeClass('clickable') 
        .addClass('notActive'); 

     }; 

    }); 

감사합니다 모든 사람이, 사람이 여기에 "작업"최종 데모를보고 싶은 경우에하는 코드에 대한 바이올린을

working version

답변

3

보정을하고,하지 않은 테스트했지만 작동해야합니다.

$(document).on("click", '.clickable', function(event){ 
    if(!$('.box').is(':animated')) { 
     var position = $(this).position(); 
     var targetPosition = $('.target').position(); 
     $(this) 
      .clone() //clone element 
      .addClass('cloned') //add class to cloned element 
      .css({ 
       'position' : 'absolute' 
      , 'top' : position.top 
      , 'left' : position.left 
      }) 
      .appendTo('body'); //append to the document 
      animate(position,targetPosition); 
      $(this) 
       .removeClass('clickable') 
       .addClass('notActive') 
       .off('click'); 
    }; 
});