我有一个
jquery功能来改变鼠标悬停上的图像的不透明度以产生脉动效果,但是我想改变它,以便图像一旦加载就会脉动,将鼠标悬停元素鼠标移开并鼠标移开.
这是我的代码
(function($) { $(document).ready(function() { window.pulse_image = null; window.pulse_continue_loop = false; $('.pulse_image').mouSEOver(function() { // User is hovering over the image. window.pulse_continue_loop = true; window.pulse_image = $(this); PulseAnimation(); // start the loop }).mouSEOut(function() { window.pulse_continue_loop = false; window.pulse_image.stop(); window.pulse_image.css('opacity',1); }); }); })(jQuery); function PulseAnimation() { var minOpacity = .33; var fadeOutDuration = 650; var fadeInDuration = 650; window.pulse_image.animate({ opacity: minOpacity },fadeOutDuration,function() { window.pulse_image.animate({ opacity: 1 },fadeInDuration,function() { if(window.pulse_continue_loop) { PulseAnimation(); } }) }); }
解决方法
(function($) { $(document).ready(function() { window.pulse_image = $('.pulse_image'); window.pulse_continue_loop = true; PulseAnimation(); // start the loop }); })(jQuery);