I have created two functions which will allow me to use them with different CSS classes.
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'})
});
}
However, only the function expandBox seems to work. If I hover my mouse away the from the .orange element the box does not contract.
I want these animations to appear as functions as I plan to use them few times within my website. If I put my code like below:
$(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'})
});
});
Everything seems to work ok. Is there a reason why the first code does not work but the second one does?
Thanks,
vnayak