$(document).ready(function() { $("a.pulsate").each(function() { var pulser = $(this); var intervalID = setInterval(function() { pulsate(pulser); }, 10000); $(this).data("intervalID", intervalID); }); $('a.pulsate') .mouseenter(function() { // Stop pulsating $(this).stop() .animate({opacity: 1}, 1) .addClass('stop-pulsing'); clearInterval($(this).data("intervalID")); }) .mouseleave(function() { // Start pulsating again $(this).removeClass('stop-pulsing'); var pulser = $(this); var intervalID = setInterval(function() { pulsate(pulser); }, 3000); $(this).data("intervalID", intervalID); }); }); function pulsate(pulser) { if (!pulser.hasClass('stop-pulsing')) { pulser.animate({opacity: 0.1}, 1000, 'linear') .animate({opacity: 1}, 1000, 'linear'); } }