gpt4 book ai didi

jquery - 使 jquery 函数在页面加载时运行

转载 作者:行者123 更新时间:2023-12-03 21:54:00 25 4
gpt4 key购买 nike

我有一个 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);​

关于jquery - 使 jquery 函数在页面加载时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12468374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com