如何控制动画速度jquery

时间:2017-04-13 13:38:48

标签: javascript jquery

我有两个函数,一个是控件的动画 animate_as()另一个是使用ajax get_speed()从数据库中获取动画值。

get_speed()函数中,我从数据库中获取值并将其存储在隐藏的输入标记 txtspeedvalue 中,并在 animate_as()中使用此隐藏标记功能

如果我运行代码,它运行顺利。当我改变数据库中的速度时,它不会反映在动画中。

$(document).ready(function(e) {
   var winwith=$("#animate").width();

    var str1="+=";
    var str2=winwith-42; // image with 42
    var str3="px";
     var res = str1.concat(str2, str3);
    get_speed();
    var x = parseInt($("#txtspeedvalue").val());
    animate_as(x);

    function animate_as(speed_as) {
    $("#animate").animate({
            backgroundPositionX: res,
            backgroundPositionY: "+=0px"
        },speed_as);

        $("#animate").animate({
            backgroundPositionX: "0px",
            backgroundPositionY: "0px"
        },speed_as);

        speed_as= parseInt($("#txtspeedvalue").val());
        animate_as(speed_as);
    }

function get_speed(){

    var uid = localStorage.getItem('userid');
    var getvalue = $.ajax({
        type: "POST",
        url: "ajax/get_user_info.php",
        data: {uid:uid},
        async: false
    }).success(function(){
        setTimeout(function(){get_speed();}, 5000);
    }).responseText;

    document.getElementById("divspeed").innerHTML = getvalue;

   // $("#txtspeed").val(getvalue);
    $("#txtspeedvalue").val(getvalue);
}



function setuserid(uid) {
    localStorage.setItem('userid', uid);
}

});

0 个答案:

没有答案