Cool Guy Yo
Cool Guy Yo

Reputation: 6110

How would I slow down the animation of this jquery slider

I have the following code which I got from http://css-tricks.com/startstop-slider/ I have it all working you can view it at http://www.mrskitson.ca/revised with username:stack & password:stack What I want to do is slow down the animation rate I can change how long it delays in between but the animation it self is to fast and seems abrupt. Thanks in advance

// SET THIS VARIABLE FOR DELAY, 1000 = 1 SECOND
var delayLength = 5000;

function doMove(panelWidth, tooFar) {
    var leftValue = $("#mover").css("left");

    // Fix for IE
    if (leftValue == "auto") { leftValue = 0; };

    var movement = parseFloat(leftValue, 10) - panelWidth;

    if (movement == tooFar) {
        $(".slide img").animate({
            "top": -600
        }, function() {
            $("#mover").animate({
                "left": 0
            }, function() {
                $(".slide img").animate({
                    "top": 40
                });
            });
        });
    }
    else {
        $(".slide img").animate({
            "top": -600
        }, function() {
            $("#mover").animate({
                "left": movement
            }, function() {
                $(".slide img").animate({
                    "top": 40
                });
            });
        });
    }
}

$(function(){

    var $slide1 = $("#slide-1");

    var panelWidth = $slide1.css("width");
    var panelPaddingLeft = $slide1.css("paddingLeft");
    var panelPaddingRight = $slide1.css("paddingRight");

    panelWidth = parseFloat(panelWidth, 10);
    panelPaddingLeft = parseFloat(panelPaddingLeft, 10);
    panelPaddingRight = parseFloat(panelPaddingRight, 10);

    panelWidth = panelWidth + panelPaddingLeft + panelPaddingRight;

    var numPanels = $(".slide").length;
    var tooFar = -(panelWidth * numPanels);
    var totalMoverwidth = numPanels * panelWidth;
    $("#mover").css("width", totalMoverwidth);

    $("#slider").append('<a href="#" id="slider-stopper">Stop</a>');

    sliderIntervalID = setInterval(function(){
        doMove(panelWidth, tooFar);
    }, delayLength);

    $("#slider-stopper").click(function(){
        if ($(this).text() == "Stop") {
            clearInterval(sliderIntervalID);
            $(this).text("Start");
        }
        else {
            sliderIntervalID = setInterval(function(){
                doMove(panelWidth, tooFar);
            }, delayLength);
            $(this).text("Stop");
        }

    });

});

Upvotes: 2

Views: 3096

Answers (1)

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

The first parameter after the } is assumed to be the time in milliseconds. Adjust accordingly to your purpose.

$(".slide img").animate({
            "top": -600
        }, 500, function() {...

Upvotes: 2

Related Questions