too much recursion in javascript with jquery mouseover
Posted
by Stacia
on Stack Overflow
See other posts from Stack Overflow
or by Stacia
Published on 2010-01-25T23:47:03Z
Indexed on
2010/03/17
15:01 UTC
Read the original article
Hit count: 277
JavaScript
|jQuery
I am a JS novice. Using some code I found here to help me with mouseover scale/rotate images but now when I try to apply it to more than one object I'm getting errors saying "too much recursion". Before the function didn't take any arguments, it just was on s_1 and it worked fine. I am tempted to just write different code for each object but that isn't very good programming practice.
var over = false;
$(function(){
$("#s_1").hover(function(){
over = true;
swing_left_anim("#s_1");
}, function(){
over = false;
});
$("#np_1").hover(function(){
over = true;
swing_left_anim("np_1");
}, function(){
over = false;
});
});
function swing_left_anim(obj){
$(obj).animate({
rotate: '0deg'
}, {
duration: 500
});
if (over) {
$(obj).animate({
rotate: '25deg'
}, 500, swing_right_anim(obj));
}
}
function swing_right_anim(obj){
$(obj).animate({
rotate: '-25deg'
}, 500, swing_left_anim(obj));
}
© Stack Overflow or respective owner