I have some experimental script, that makes an animation of a ul
list element background-position, when the list element is hovered. Is there another way to manage this task? Or just optimize this code?
I want to make a menu that has elements with an animated background and have an idea about rotoscope style design or something in that direction. I'm thinking in cross-browser compatibility way too (: In this stage this code runs fine in Opera, Internet Explorer 6, Chrome, Firefox 2.0, and Firefox 4.0.
$(document).ready(function(){
$("li.animate").hover(
function () {
var param = '0 0';
ids = setInterval(function() {
if ( c >= 5 ) {
c = 1;
$('.animate').css('backgroundPosition', '0 0');
}
else {
param = (-100 * c++ )+'px 0';
//alert(param);
$('.animate').css('backgroundPosition', param);
if ( c > 4 ) $('.animate').css('backgroundPosition', '0 0');
}
}, 40);
},
function () {
$('.animate').css('backgroundPosition', '0 0');
clearInterval(ids);
}
);
});