I want to link color to change on hover continuously, but it never works how I want it to - it won't stop on mouseleave/hover out, which you can see, in this fiddle:
var interv;
function changeColors(item) {
interv = setInterval(function() {
$(item).animate({
color: 'red'
}, 1000)
.animate({
color: 'green'
}, 1000);
}, 100);
};
$(document).ready(function() {
$('a')
.mouseenter(function() {
changeColors(this);
})
.mouseleave(function() {
clearInterval(interv);
$(this).removeAttr("style");
});
});
Then I tried to recreate what this comment suggested, but as you can see in this fiddle, it's not working either:
$(document).ready(function() {
var interval;
$('a').hover(
function() {
if (interval)
clearInterval(interval);
interval = setInterval(function() {
$('a').animate({
color: 'red'
}, 1000)
.animate({
color: 'green'
}, 1000);
}, 10);
},
function() {
clearInterval(interval);
interval = null;
$(this).removeAttr("style");
}
);
});