在jquery中添加两个div之间的延迟

时间:2013-09-07 19:07:18

标签: javascript jquery html css delay

我有两个Div(class =切片),每个都有三个图像(class = tile)。 当我使用jquery进行动画制作时,我无法在切片类之间添加延迟。 但是我在瓷砖之间增加了延迟。

的index.html

<!DOCTYPE html> 
     <html>
        <head>
            <title>Testing Scripts</title>
            <link rel="stylesheet" type="text/css" href="style.css">
        </head>
        <body>




        <div id="slider-wrap">
            <div class="sliced">

                    <div class="tile"><img src="http://imageshack.us/a/img545/9813/58zj.jpg" alt"1"></div>
                    <div class="tile tile1"><img src="http://imageshack.us/a/img818/5776/8ik6.jpg" alt"1"></div>
                    <div class="tile tile2"><img src="http://imageshack.us/a/img18/6017/rue6.jpg" alt"1"></div>
            </div>  
            <div class="sliced " >

                    <div class="tile"><img src="http://imageshack.us/a/img163/6131/ld3f.jpg" alt"1"></div>
                    <div class="tile tile1"><img src="http://imageshack.us/a/img838/4102/h0nv.jpg" alt"1"></div>
                    <div class="tile tile2"><img src="http://imageshack.us/a/img833/6500/dp5e.jpg" alt"1"></div>
            </div>  
         </div>   


         </div>
        <script src="jQuery.js"></script>
        <script src="jquery.easing.1.3.js"></script>
        <script src="script.js"></script>
        <script>$('.sliced').slider();</script><!--Calling plugin with   -->
        </body> 
     </html>

CSS

body {
    width: 960px;
    margin: 100px auto;
    font-family: helvetica;
    font-size: 20px;
 }

#animate {
    width: 100px;
    height: 30px;
    margin-bottom: 10px;
    font-size: 16px;
}
.sliced {
    position: relative;
    margin: 5px 5px;
    width: 900px;
    height: 200px;
    border: 2px solid black;
    }
.box {
    width: 600px;
    border: 2px solid rgba(0,0,0,.05);
    padding: 10px 10px;
}

img {
    width: 270px;
    height: 150px;

}
.tile {
    position: absolute;
    float: left;
    margin: 25px 15px;
}
.tile1 {

    left: 280px;

}
.tile2 {

    left: 560px;

}

JScript: -

function Slider(ele){
    var $ele = $(ele), //Jquery Object of .sliced class
        $tiles = $ele.find('.tile');  //$tiles contains all .tile class as jquery Object
        $.each($tiles,function(index,value){ 
               setTimeout(function(){
                $(value).fadeOut(1000);
                },1000*index);

        });

} 

$.fn.slider = function(){   
       //This stores all .sliced class as Jquery object                                      
    return this.each(function(){  //Iterarting over each class provided 
        var slider = new Slider(this);  //Slider is constructor function
        //console.log(slider);
    });
}

2 个答案:

答案 0 :(得分:0)

经过这么多的打击和试验,我自己想出来了

JS: -

function Slider(ele,index){
    var $ele = $(ele), //Jquery Object of .sliced class
        $tiles = $ele.find('.tile'),//$tiles contains all .tile class as jquery Object
        delay = 5000;  //Delay between two divs
        setTimeout(function(){
             $.each($tiles,function(index,value){ 
               setTimeout(function(){
                $(value).fadeOut(1000);
                },1000*index);
          });
        },delay*index);


} 

$.fn.slider = function(){   
       //This stores all .sliced class as Jquery object                                      
    return this.each(function(index){  //Iterarting over each class provided 
        var slider = new Slider(this,index);  //Slider is constructor function
        //console.log(slider);
    });
}

答案 1 :(得分:-1)

也许是这样的

$( "div" ).click(function() {
  $( this ).addClass( "big-blue", 1000, "easeOutBounce" );
});

可以帮忙吗?