开发者

Creating a loop that fades out each article in succession. jQuery

开发者 https://www.devze.com 2023-03-20 08:22 出处:网络
So the idea is to fade each image out from the bottom.. obviously it\'s going to have to backwardly traverse the array. However, i can\'t seem to figure it out at the moment. The idea is that it would

So the idea is to fade each image out from the bottom.. obviously it's going to have to backwardly traverse the array. However, i can't seem to figure it out at the moment. The idea is that it would pause after r开发者_JS百科unning the fadeOut() function, I thought set time out would work, but firebug gives me this error: useless setTimeout call (missing quotes around argument?)

Line 262. I even went as far as to not use a $.each loop and use a for (i=0 loop

<script type="text/javascript">
    //Bottom Nav functions
    $(document).ready(function(){

        $('#bottomNav a:eq(0)').click(function(){

        var arti = $('#aHolder article');
        var amt = arti.length;
        var i = 0;

            for (i=0;i<amt;i++){

            $('#aHolder article:eq('+i+')').fadeOut();
            setTimeout(300);

            }


        });

    });


</script>


Something like this should do:

var i = $('#aHolder article').length,
interval = setInterval(function () {
    if (i-- <= 0) {
        clearInterval(interval);
        return;
    }
    $('#aHolder article:eq(' + i + ')').fadeOut();
}, 300);

Delayed execution in a loop is best done with an interval. Once you have reached your terminating condition, you just clear it.

0

精彩评论

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