Skip to content Skip to sidebar Skip to footer

Setting A Time For Flicker Animation On Img

I'm using this code to make my logo flicker on my website. But It becomes annoying when it continues to flicker while browsing, how can I set a time to allow it to flicker for some

Solution 1:

You could have a counter, which you then use to decide whether you want to set another timeout. As a side note, you should never add functions to window and then passing a string to setTimeout. Always just pass the function itself:

$(document).ready(function(){
    var t;
    var amount = 0;
    const fparam = 100;
    const uparam = 100;

    functiontimeout(f, t) {   // this function delegates setTimeoutif(amount++ < 150) {   // and checks the amount already (un)flickeredsetTimeout(f, t); // (150 * 100 ms = 15 s)
        }
    }

    var flickr = function(){
        if(Math.round(Math.random())){
            $("#logodcoi").css("visibility","hidden");
            t = timeout(unflickr,uparam);
        }
        else
            t = timeout(flickr,fparam);
    };

    var unflickr = function(){
        if(Math.round(Math.random())){
            $("#logodcoi").css("visibility","visible");
            t = timeout(flickr,fparam);
        }
        else
            t = timeout(unflickr,uparam);
    };

    t = timeout(flickr,fparam);
});

Solution 2:

I see you're using jquery, you could use the following, if I remember correctly, all the stuff I use below has been in jquery since 1.0, so you should be good:

counter = 1;
functionhideOrShow(){
             $(".classToSelect").animate({"opacity": "toggle"}, 100);
             counter = counter +1;
             if (counter >= 21) clearInterval(flickerInterval);
}
flickerInterval = setInterval(hideOrShow, 100);    

Change the selector, animation duration, and variable names to whatever you fancy/need.

Post a Comment for "Setting A Time For Flicker Animation On Img"