创建一个动画序列循环jquery [英] Create an animation sequence loop jquery

查看:97
本文介绍了创建一个动画序列循环jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个连续循环的动画,一个div img淡入,然后下一个淡出的最后一个这是我到目前为止。

I'm trying to create a continuous looping animation whereby one div img fades in and then the next fading out the last one this is what I have so far.

JavaScript:

function fadeLoop() {
    $(".circle img").each(function(index) {
        $(this).delay(1000*index).fadeIn(500);
    });
};

$('.circle').delay(2000).fadeIn(2000,function() {        
    fadeLoop();
});

HTML:

<div class="circle" id="first-circle">
    <img src="test.jpg"/>
    <a href="">ART</a>
</div>
<div class="circle" id="second-circle">
    <img src="test.jpg"/>
    <a href="">FASHION</a>
</div>
<div class="circle" id="third-circle">
    <img src="test.jpg"/>
    <a href="">DECOR</a>
</div>

CSS:

.circle { border-radius:300px; width:300px; border:5px solid #ccc; height:300px;margin:10px; padding:0px; float:left; display:none; position:relative; }
.circle a { position:relative; z-index:999; margin:0 auto; line-height:300px; display:block; width:300px; text-align:center; font-family: sans-serif; font-weight:normal; text-transform:capitalize; color:#fff; font-size:60px; text-decoration:none; }
#first-circle img, #second-circle img, #third-circle img { display:none; }
#first-circle { background:#803131; }
#second-circle { background:#751c20; }
#third-circle { background:#803131; }
#first-circle img { border-radius:300px; width:300px; height:300px; position:absolute; top:0px; left:0px;}
#second-circle img { border-radius:300px; width:300px; height:300px; position:absolute; top:0px; left:0px;}
#third-circle img { border-radius:300px; width:300px; height:300px; position:absolute; top:0px; left:0px;}

Live demo: jsFiddle

Live demo: jsFiddle

我确定这不是那么遥远需要做的是淡出最后一个,在下一个我有一个序列,但需要扩展它,并使其循环。

I'm sure this can't be that far off all I need to do is fade out the last one and in the next one I have a sequence but need to expand it and make it loop.

推荐答案

这可能有助于您

$(function(){
    (function(){
        var circles=$('.circle'), i=0;
        function shuffle()
        {
            $(circles[i]).fadeIn(2000, function(){
                i=(i < circles.length-1) ? (i+1) : 0;
                setTimeout(function(){
                    $('.circle').fadeOut(2000);
                    shuffle();
                }, 2000);
            });
        }
        shuffle();
    })();
});​

DEMO

这篇关于创建一个动画序列循环jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆