我如何减慢这个jquery滑块的动画速度

时间:2010-12-22 01:26:51

标签: jquery animation performance

我有以下代码来自http://css-tricks.com/startstop-slider/我已经完成所有工作,您可以在http://www.mrskitson.ca/revised使用用户名:stack&密码:堆栈 我想要做的是减慢动画速度我可以改变它之间的延迟时间,但动画本身就是快速而且看起来很突然。提前致谢

// 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");
        }

    });

});

1 个答案:

答案 0 :(得分:2)

假设}之后的第一个参数是以毫秒为单位的时间。根据您的目的进行调整。

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