Created
July 18, 2012 19:41
-
-
Save tim-evans/3138375 to your computer and use it in GitHub Desktop.
SC animation scheduler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SC._animationBuffer = []; | |
| /** | |
| If you try to animate a view that was previously | |
| `isVisible`: `NO`, you have to set the view to be | |
| `isVisible`: `YES`, then at the *next* run loop, | |
| try to animate the view, but only after forcing | |
| the browser to repaint the view. | |
| This function does all that for you, albeit | |
| causing a callback pyramid. | |
| */ | |
| SC.scheduleAnimation = function (view, callback) { | |
| if (SC.platform.supportsCSSTransitions) { | |
| var self = this, | |
| bufLen = this._animationBuffer.length; | |
| this._animationBuffer.push(callback); | |
| if (!bufLen) { | |
| this._pendingAnimation = setTimeout(function () { | |
| // Chrome workaround; | |
| // Breaks up the repaint buffer | |
| view.get('layer') && view.get('layer').offsetHeight; | |
| SC.run(function () { | |
| var buffer = self._animationBuffer, | |
| len = buffer.length, | |
| i; | |
| for (i = 0; i < len; i++) { | |
| buffer[i](); | |
| } | |
| }); | |
| self._animationBuffer = []; | |
| }, 0); | |
| } | |
| } else { | |
| callback(); | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment