开发者

Making a loop with opacity and li items

开发者 https://www.devze.com 2023-02-11 05:18 出处:网络
I have this javascript code // Elke keer een logo meer opacity开发者_如何转开发 geven var randomnumber=Math.floor(Math.random()*$(\"#main .logolint ul li\").children().length);

I have this javascript code

// Elke keer een logo meer opacity开发者_如何转开发 geven
    var randomnumber=Math.floor(Math.random()*$("#main .logolint ul li").children().length);
    $(function() {
        // geef de logo's een opacity van 0.5
        $("#main .logolint ul li > img").css({opacity: 0.5});

        //set timeout for image to appear (set at 500ms)
        setTimeout(function(){
           //fade in the random index of the image collection
           $("#main .logolint ul li > img:eq(" + randomnumber + ")").css({opacity: 1.0});
        }, 500);       
    });

This code give my list items a opacity from 0.5. And give a random list item an opacity for 1.0.

But how can i make this script. That he give over 5 sec. A other li item a opacity from 1? How can i make a loop in this script?


Change setTimeout, to setInterval, same code, just different function name. setInterval calls the function at a set interval (thus a loop).

You might also want to change the opacity call to fadeIn , then you get a nice fade in effect, instead of a sudden change from 0.5 to 1.

Also you might want to save the setInterval "pointer":

var pntr = setInterval(xxx);

So that when your loop is done (and everything is visible), you can call 'clearInterval(pntr)` to stop the interval.

0

精彩评论

暂无评论...
验证码 换一张
取 消