Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slow down an jquery animation

I have an animation that i have been trying to slow down but so far i have been unsucsessful i have tried duration and adding the time at the end however the animation seems to run at the same speed.

any help would be great.

$("document").ready(function(){
    // Change the width of the div
    var i = 0;
    $(".progress-bar span").animate({
        width: "100%"
        },
        {step: function(){
        //console.log( "width: ", i++ );
        console.log($(this).width());
        },
         complete : function(){
             console.log("finished");
         }
        },2000);
});

see fiddle here http://jsfiddle.net/Jrand/8jXDK/2/

like image 532
James Rand Avatar asked Jun 03 '26 08:06

James Rand


2 Answers

You just need to set the duration argument for the animation as part of the second argument which is the options object. jQuery's .animate() takes several forms. The form you are using takes two objects and the second object can include the duration as a property of that second argument like I show here:

$("document").ready(function(){
    // Change the width of the div
    var i = 0;
    $(".progress-bar span").animate({
        width: "100%"
        },
        {
            duration: 5000,
            step: function() {
                //console.log( "width: ", i++ );
                console.log($(this).width());
            },
            complete: function() {
                 console.log("finished");
            }
     });
});
like image 129
jfriend00 Avatar answered Jun 04 '26 23:06

jfriend00


Try this,

$("document").ready(function(){
// Change the width of the div
var i = 0;
$(".progress-bar span").animate({
    width: "100%"

    },
    {
        duration: 5000,
        step: function(){
                //console.log( "width: ", i++ );
                console.log($(this).width());
            },
         complete : function(){
             console.log("finished");
         }
    });
 });

Your updated jsfiddle code >> http://jsfiddle.net/8jXDK/4/

like image 41
amrinder007 Avatar answered Jun 05 '26 01:06

amrinder007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!