Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm trying to create a webpage in which i've a few span elements which is expected to slideDown one by one. But i'm not able to control the animation and it's getting executed all at the same time. I've the sample code which tried with, below.

Below is the body.

HTML
<body>
    <div id="Line1">
        <br />
        <br />
        <br />
        <span id="spanA" style="background-color: Red; width: 10px; height: 18px;"></span>
        <br />
        <br />
        <span id="spanB" style="background-color: Red; width: 20px; height: 8px;"></span>
        <br />
        <br />
        <span id="spanC" style="background-color: Red; width: 30px; height: 8px;"></span>
        <br />
        <br />
        <span id="spanD" style="background-color: Red; width: 40px; height: 8px;"></span>
        <br />
        <br />
        <span id="spanE" style="background-color: Red; width: 50px; height: 8px;"></span>
        <br />
        <br />
        <span id="spanF" style="background-color: Red; width: 60px; height: 8px;"></span>
        <br />
        <br />
        <span id="spanG" style="background-color: Red; width: 70px; height: 8px;"></span>
        <br />
        <br />
    </div>
</body>


and the jQuery part

JavaScript
$(document).ready(function() {
      $("div span").animate({ width: '+=50px' }, {
          speed: "slow",
          easing: "linear",
          step: function() { setTimeout('', 1000) },
          queue: false
      });
  });


Can anyone please tell me if there is any mistake in the code/syntax or if there is a better way to queue animation?

Thanks,
Daion
Posted

Hi,

Try this! Maybe this is what you want to achieve...
You can simulate queue!? Change delay variable to desired value to get effect you like...
JavaScript
$(document).ready(function() {

    var delay = 500;
    $("div span").each(function() {
        var item = $(this);
        queueElementAnimation(item, delay);
        delay += 500;
    });

});

function queueElementAnimation($el, deley) {
    setTimeout(function() {
        $el.animate({
            width: '+=50px'
        }, {
            speed: "fast",
            easing: "linear"
        });
    }, deley);
}
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 9-Feb-12 16:04pm    
Works, a 5.
--SA
DieOnTime 11-Feb-12 23:37pm    
Thanks alot martin. I carved out almost the same code. it works absolutely fine..
I'm not sure of the relevance of this parameter, but you do realize you set queue to false in your call to the animate function? Have you tried to set it to true?

Regards,

Manfred
 
Share this answer
 
Comments
DieOnTime 9-Feb-12 8:33am    
yes manfred, i did and found no difference..
DieOnTime 9-Feb-12 8:34am    
can you please give a syntax/code which will make the animation execute in a queue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900