简体   繁体   中英

Javascript/jquery fade effect decay

Pretty specific one this time, I have the following code to loop some fades depending on conditions, as you can see depending on the state the animation differs slightly.

At the moment it is producing the effect I want but it seem's to slow down gradually until at around 3 minutes it stops completely.

I've gotten to the point where I can't stare at it any longer! can anyone offer me some advice on how to make this a continuous loop?

Here's a fiddle: http://jsfiddle.net/CbNc5/

var glimmerLen = 16;
var initiated = false;
var animateLoop = false;
var timeout;


function glimmerAnimate() {
if (!initiated) {
    timeout = window.setTimeout(function() {glimmerAnimate();}, 2500);
    initiated = true;

} else if (!animateLoop && initiated) {
    $("#glimmer li").fadeTo(1500, 0.5, function(){
        glimmerAnimate();
        animateLoop = true;
    });
} else if (animateLoop) {
    var rangeMax = glimmerLen + 1;
    var randObj = Math.floor(Math.random() * rangeMax);

    $("#glimmer-" + randObj).fadeTo(1500, 0.8, function() {
        $("#glimmer-" + randObj).fadeTo(2000, 0.2);
            glimmerAnimate();
    });
}


}

I have rewrite this, hope this help ( http://jsfiddle.net/CbNc5/5/ )

function fadeLoop(e) {
    $(e).fadeTo(Math.random() * 500, 0.2, function () {
        $(this).fadeTo(Math.random() * 500, 1, function () {
            fadeLoop(this);
        });
    });
}

$('li').each(function () {
    fadeLoop(this);
});

PS If you only want loop opacity, you can use CSS3, it will be more simple

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM