我有一个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();
}
})
});
}
从
http://www.infinitywebcreations.com/2011/01/how-to-create-a-throbbingpulsing-image-effect-with-jquery/
最佳答案
(function($) {
$(document).ready(function() {
window.pulse_image = $('.pulse_image');
window.pulse_continue_loop = true;
PulseAnimation(); // start the loop
});
})(jQuery);