2011-04-15 48 views
0

我知道unwrap(),但是,我似乎無法讓它工作。試圖解開img

我雙擊一個img。它用div包裹,並且在這個包裹的img上方插入一個div。這是爲了動畫的目的。預先設定的div移動。動畫完成後,我需要全部撤消。目前,我有一個條款,如果img再次被dblclicked,動畫div被刪除,但包裝仍然存在。

$("#L .A, .B").live('dblclick', function(event) { 
    if (event.type === 'dblclick') { 
     if ($(this).hasClass('R')) { 
      $('#Box').find('.M').remove(); 
     } else { 
      $(this).wrap('<div class="MContain" />'); 
      $(this).parent().prepend('<div class="M" />'); 
      $(".M").stop().animate({ 
        marginTop : '-5px' 
       }, 400).animate({ 
        opacity : '0' 
       }, 400); 
     } 
     $(this).toggleClass('R'); 
     $('.MContain').children().unwrap(); 
    } 
}); 

任何提示?

回答

1
$(".M").stop().animate({ 
    marginTop: '-5px' 
}, 400).animate({ 
    opacity: '0' 
}, 400).queue(function() { 
    //This will be ran after the animation is done, add your code here. 
}); 
+0

@Peeter;隊列對於移除動畫div非常有用,但是我仍然無法解開img。我嘗試從.M解包,因爲它的父母與img是一樣的,但也沒有運氣。 – 2011-04-15 18:53:28