使jquery功能在页面加载时运行

前端之家收集整理的这篇文章主要介绍了使jquery功能在页面加载时运行前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个 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相关文章