Skip to content

Instantly share code, notes, and snippets.

@tim-evans
Created July 18, 2012 19:41
Show Gist options
  • Select an option

  • Save tim-evans/3138375 to your computer and use it in GitHub Desktop.

Select an option

Save tim-evans/3138375 to your computer and use it in GitHub Desktop.
SC animation scheduler
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