我已經創建了兩個函數,它們允許我將它們用於不同的CSS類。jquery函數不顯示動畫
var CSSElement;
$(document).ready(function(){
expandBox (".orange");
minimizeBox(".orange");
});
function expandBox ($CSSElement){
//When mouse rolls over
$($CSSElement).mouseover(function(){
$(this).stop().animate({height:'485px'},{queue:false, duration:600, easing: 'easeOutBounce'})
});
}
function minimizeBox ($CSSElement){
//When mouse is removed
$(CSSElement).mouseout(function(){
$(this).stop().animate({height:'50px'},{queue:false, duration:600, easing: 'easeOutBounce'})
});
}
但是,只有函數expandBox似乎工作。如果我將鼠標懸停在.orange元素上,那麼該框不會收縮。
我希望這些動畫顯示爲功能,因爲我打算在我的網站中多次使用它們。如果我把我的代碼如下:
$(document).ready(function(){
//When mouse rolls over
$($CSSElement).mouseover(function(){
$(this).stop().animate({height:'485px'},{queue:false, duration:600, easing: 'easeOutBounce'})
});
//When mouse is removed
$(CSSElement).mouseout(function(){
$(this).stop().animate({height:'50px'},{queue:false, duration:600, easing: 'easeOutBounce'})
});
});
一切似乎工作正常。第一個代碼不起作用,但第二個代碼有效的原因是什麼?
感謝,
vnayak
能否請您提供一套完整的信息,即HTML和jQuery部分,也概括了它的jsfiddle? – 2013-05-12 22:50:05