2013-12-10 38 views
0
$('.imgc').hover(
    function(e) {        
     $(this).effect("bounce", { times:5 }, "slow"); 

    }, 
    function(e) { 
    $(this).unbind('mouseenter'); 
}); 

我需要對圖像設置一個效果。但是我需要這種效果只能一次工作。但是之後我需要在mouseout上再次綁定。但它不起作用。如何解除綁定然後再綁定?

('.imgc').bind('mouseenter', e); 

我該怎麼做?

+0

爲什麼不使用http://api.jquery.com/on/和http://api.jquery.com/off/作爲'bind'和'unbind'已被棄用 – exexzian

+1

我想如果你解釋一下更多你正在尋找的東西,你不應該需要解除事件 –

+0

請嘗試http://api.jquery.com/one/ – Stefan

回答

0

嘗試像

$('.imgc').on('hover', function(e) {        
     $(this).one(function() { 
       $(this).effect("bounce", { times:5 }, "slow"); 
     }); 
     $(this).off('mouseenter'); 
    }, 
    function(e) { 
     $(this).on('mouseenter'); 
}); 
+0

不要工作。首次懸停時,它不起作用。在2它重複。 – user3008628

0

你應該試試這個,

$(".imgc").on({ 
    mouseenter:function(){ 
     $(this).effect("bounce", { times:5 }, "slow"); 
    }, 
    mouseleave:function(){ 
    } 
}); 

懸停基本上是一個pseudoevent,它映射到的mouseenter鼠標離開