滚动时的Jquery延迟

时间:2014-03-13 04:47:32

标签: javascript jquery html css

嗨我有一组图标,我想在向下滚动时逐一显示。

我使用http://www.justinaguilar.com/animations/作为动画。

如何在我的jquery上添加延迟功能,以便逐个显示? 任何可以替代这种效果的插件?

有什么建议吗?

谢谢你们

enter image description here

html代码

     <div id="create" class="col-lg-15 col-md-15 col-xs-12 col-sm-12 ac m-t20 m-b20">
                    <img src="//placehold.it/80x80" alt="folder" class="img-circle">
                    <div class="clear"></div>
                    <i class="fa fa-user fa-5x m-t10"></i>
                    <h4>Create an account</h4>
                </div>

                <div id="define" class="col-lg-15 col-md-15 col-xs-12 col-sm-12 ac m-t20 m-b20">

                    <img src="//placehold.it/80x80" alt="folder" class="img-circle">
                    <div class="clear"></div>
                    <i class="fa fa-pencil-square-o fa-5x m-t10"></i>
                    <h4>Define your API</h4>

                </div>

                <div id="sync" class="col-lg-15 col-md-15 col-xs-12 col-sm-12 ac m-t20 m-b20">

                    <img src="//placehold.it/80x80" alt="folder" class="img-circle">
                    <div class="clear"></div>
                    <i class="fa fa-refresh fa-5x m-t10"></i>
                    <h4>Sync the local client</h4>

                </div>

                <div id="cloud" class="col-lg-15 col-md-15 col-xs-12 col-sm-12 ac m-t20 m-b20" >

                    <img src="//placehold.it/80x80" alt="folder" class="img-circle">
                    <div class="clear"></div>
                    <i class="fa fa-cloud fa-5x m-t10"></i>
                    <h4>Get data from the cloud</h4>

                </div>

                <div id="scale" class="col-lg-15 col-md-15 col-xs-12 col-sm-12 ac m-t20 m-b20">

                    <img src="//placehold.it/80x80" alt="folder" class="img-circle">
                    <div class="clear"></div>
                    <i class="fa fa-bar-chart-o fa-5x m-t10"></i>
                    <h4>Scale as required</h4>

                </div>

css代码

#create, #define, #sync, #cloud, #scale
{
  visibility:hidden;
}

jquery代码

$(window).scroll(function () {
    $('#kinect-logo').each(function () {
        var imagePos = $(this).offset().top;
        var topOfWindow = $(window).scrollTop();
        if (imagePos < topOfWindow + 400) {
            $(this).addClass("slideUp");
        }
    });
    $('#create').each(function () {
        var imagePos = $(this).offset().top;
        var topOfWindow = $(window).scrollTop();
        if (imagePos < topOfWindow + 400) {
            $(this).delay(300).addClass("fadeIn");
        }
    });
    $('#define').each(function () {
        var imagePos = $(this).offset().top;
        var topOfWindow = $(window).scrollTop();
        if (imagePos < topOfWindow + 400) {
            $(this).addClass("fadeIn");
        }
    });

    $('#sync').each(function () {
        var imagePos = $(this).offset().top;
        var topOfWindow = $(window).scrollTop();
        if (imagePos < topOfWindow + 400) {
            $(this).addClass("fadeIn");
        }
    });

    $('#cloud').each(function () {
        var imagePos = $(this).offset().top;
        var topOfWindow = $(window).scrollTop();
        if (imagePos < topOfWindow + 400) {
            $(this).addClass("fadeIn");
        }
    });

    $('#scale').each(function () {
        var imagePos = $(this).offset().top;
        var topOfWindow = $(window).scrollTop();
        if (imagePos < topOfWindow + 400) {
            $(this).addClass("fadeIn").delay(300);
        }
    });
});

2 个答案:

答案 0 :(得分:1)

您可以使用javascript函数setTimeOut()

添加延迟
setTimeout(function (){
// Code you want to delay or you can call the function reference directly instead of defining one
}, 2000);

答案 1 :(得分:1)

尝试这样的事情

$(window).scroll(function () {
    $('#kinect-logo,#create,#define,#sync,#cloud,#scale').each(function (index,element) {
        var imagePos = $(this).offset().top;
        var topOfWindow = $(window).scrollTop();
        if (imagePos < topOfWindow + 400) {
            $(this).delay(index*600).queue(function(){
                $(this).addClass("slideUp").dequeue();
            });
        }
    });

});

http://jsfiddle.net/hEuC3/

http://jsfiddle.net/hEuC3/1/