0

见下文。我正在尝试function(response)作为要在进度条函数中使用的变量传递。反正就是这个想法。data = response在这种情况下,我该如何回调var i = data

$(document).ready(function () {
    $.ajaxSetup({
        cache: false
    });
    var data = 0;
    setInterval(function () {
        $('#divToRefresh').load('usercounter.php', function (response) {
            data = response;
        });
    }, 100);
    window.onload = function () {
        var Animator = new function () {
                var parent = document.getElementById('container');
                var element = document.getElementById('test');
                var target = document.getElementById('message');
                this.move = function () {
                    var i = data;
                    var width = 0;
                    var timer = window.setTimeout(function () {
                        i += 1;
                        element.style.width = width + i + 'px';
                    }, 10);
                };
            };
        Animator.move();
    };
});
4

1 回答 1

0

不确定您的动画师如何工作或这些元素如何交互,但我猜您的目标是定期调用 move 以刷新其当前状态?所以把那个放在interval里面,然后做动画的count部分的检索。不确定这是否适用于您的场景。

$(document).ready(function () {
    $.ajaxSetup({
        cache: false
    });  

    window.onload = function () {
        var Animator = new function () {
                var parent = document.getElementById('container');
                var element = document.getElementById('test');
                var target = document.getElementById('message');
                this.move = function () {
                    $('#divToRefresh').load('usercounter.php', function (response) {
                        var i = response;                      
                        var width = 0;
                        var timer = window.setTimeout(function () {
                          i += 1;
                          element.style.width = width + i + 'px';
                        }, 10);
                    });

                };
            };
        Animator.move();
        setInterval(function () {
           Animator.move();
        }, 100);
    };
});
于 2013-05-13T09:03:23.040 回答