Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue animation while tab hidden (switched to other tab) #421

Open
sendel opened this issue Apr 30, 2013 · 3 comments
Open

Continue animation while tab hidden (switched to other tab) #421

sendel opened this issue Apr 30, 2013 · 3 comments

Comments

@sendel
Copy link

sendel commented Apr 30, 2013

May be need setup config with this function, some modes:

  1. normal (as now, freeze animation while tab hidden)
  2. always (as this patch, continue animation when tab hidden by timer)
  3. fast (as idea, for transitions set it in last position and end, as normally ended)

/*******/

Kinetic.Animation.requestAnimFrame = function(callback) {
    var raf = Kinetic.DD && Kinetic.DD.isDragging ? this.fixedRequestAnimFrame : RAF;
    function getHidden(){
        var hidden, visibilityChange; 
        if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support 
            hidden = "hidden";
            visibilityChange = "visibilitychange";
        } else if (typeof document.mozHidden !== "undefined") {
            hidden = "mozHidden";
            visibilityChange = "mozvisibilitychange";
        } else if (typeof document.msHidden !== "undefined") {
            hidden = "msHidden";
            visibilityChange = "msvisibilitychange";
        } else if (typeof document.webkitHidden !== "undefined") {
            hidden = "webkitHidden";
            visibilityChange = "webkitvisibilitychange";
        }
        else
            {
                return true;
            }
        return document[hidden];

    }

    var hidden = getHidden();

    raf = hidden ? this.fixedRequestAnimFrame: raf;
    raf(callback);
};
@sendel
Copy link
Author

sendel commented Jun 11, 2013

new implementation (fast set to end of tween) for Sprite need also

/***/

    onEnterFrame: function() {
        var t = this.getTimer() - this._startTime;
        if(getHidden() && t < this.duration && t>=0)
        {
            t = this.duration;

        }
        if(this.state === PLAYING) {
            this.setTime(t);
        }
        else if (this.state === REVERSING) {
            this.setTime(this.duration - t);
        }
    },

@sendel
Copy link
Author

sendel commented Jun 11, 2013

for Sprite (not full test)

/***/

     _updateIndex: function() {
        var index = this.getIndex(),
            animation = this.getAnimation(),
            animations = this.getAnimations(),
            anim = animations[animation], 
            len = anim.length;
        if(getHidden())
        {
            index = len - 1;

        }            
        if(index < len - 1) {
            this.setIndex(index + 1);
        }
        else {
            this.setIndex(0);
        }
    }

@sendel
Copy link
Author

sendel commented Jun 20, 2013

full solution
sendel@a9036d1
&&
sendel@e68ba39

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant