2016-01-25 25 views
0

我有多個箱子一個網站,我想創建一個函數的動畫,所以我沒有把它們添加到每個箱子懸停一些有不同的動畫包括在內。查詢動畫函數調用

出於某種原因,我不能把動畫在框中,如果我在框中複製的功能代碼,並把它工作正常,但可以得到它的工作從函數調用它。

function aniIn() { 
    $(".br-t", this).stop().animate({ "width": "100%" }, 500, "easeOutQuint"), 
} 

function aniOut() { 
    $(".br-t", this).stop().animate({ "width": "0"}, 900, "easeOutQuint"), 
} 

$("a#box01").hover(function() { 
     $("#background").fadeIn(500); 
     aniIn(); 
    }, function() { 
     $("#background").stop().fadeOut(900); 
     aniOut() 
}); 

HTML:

<a href="#" id="box01" title="box"></a> 

任何幫助將是巨大的。

TJ。

+0

你說的'box'是什麼意思? – Rayon

+1

你已經在你的函數中使用了'this'。這就是爲什麼它不起作用。您需要將「this」傳遞給這兩個函數。 –

回答

2

試試下面的代碼:

function aniIn(current) { 

$(".br-t", current).stop().animate({ "width": "100%" }, 500, "easeOutQuint"), 
} 

function aniOut(current) { 
    $(".br-t", current).stop().animate({ "width": "0"}, 900, "easeOutQuint"), 
} 

$("a#box01").hover(function() { 
     $("#background").fadeIn(500); 
     aniIn(this); 
    }, function() { 
     $("#background").stop().fadeOut(900); 
     aniOut(this); 
}); 
+0

感謝瑞詩凱詩tadaka這個偉大的工程! –