English 中文(简体)
采用javascript 的固定时间进行简单的消ation
原标题:using setTimeout in javascript to do simple animation

我正在用定时办法在 Java文中制造消im,但似乎并未奏效。 只有第1次注射才得以执行,此后没有采取任何行动。

我用两种不同的手提电脑进行审判,一只手提错,但用<代码>本身。 反馈不是职能。 我也看到其他错误,比如说,当我尝试分散的方式时,我的停职职能是无用的,或者说是“comp”。 似乎没有工作。 我尝试了<条码>功能(自称){自选.animateCallback()}>和.animateCallback>(附和没有引自)。

该代码如下,是原型方法的一部分。

    increment : function(incr, target, tick) {
    var self = this;

    self.animateCallback = function()
    {
        var done = Math.abs(self.currValue - target) < Math.abs(incr);
        if(!self.animateCallback || done) {

            if(done) {
                self.updateAngle(self.currValue/self.maxValue);
                self.stopAnimation(); //just setting animateCallback to null
            }
        }
        else
        {
            self.updateAngle((self.currValue+incr)/self.maxValue);
            setTimeout(self.animateCallback, tick);
        }

    }
    self.animateCallback.call();
},
最佳回答

我感觉到,问题与通过关闭和财产获得该功能的<条码>(自称“Callback...)有关。 至少应该这样做:

increment : function(incr, target, tick) {
    var self = this;

    var animateCallback = function()
    {
        var done = Math.abs(self.currValue - target) < Math.abs(incr);
        if(done) {
            self.updateAngle(self.currValue/self.maxValue);
            self.animateTimeout = null;
        }
        else
        {
            self.updateAngle((self.currValue+incr)/self.maxValue);
            self.animateTimeout = setTimeout(animateCallback, tick);
        }

    }
    animateCallback();
},
stopAnimation: function() {
    if (this.animateTimeout) {
        clearTimeout(this.animateTimeout);
        this.animateTimeout = null;
    }
},
问题回答

我认为,错误是,其他一些法典正在将<代码>本身.animateCallback的价值改为其他法。 第一次通过<条码>准时对<条码>本身具有正确价值。 这一点已经变成了其他东西,而后者只是一种功能,但仍然是一种非麻风价值,因此,<代码>!

如果说:

if((typeof self.animateCallback !== "function") || done) {

    if(done) {
        self.updateAngle(self.currValue/self.maxValue);
        self.stopAnimation(); //just setting animateCallback to null
    }
}

试图通过匿名功能,以<代码> 每日,如:

setTimeout(function(){ self.animateCallback(); }, tick);

希望它能够提供帮助。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签