Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active February 11, 2018 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebReflection/574ae00d82c97b36176355fa070c036b to your computer and use it in GitHub Desktop.
Save WebReflection/574ae00d82c97b36176355fa070c036b to your computer and use it in GitHub Desktop.
Grants UI setup and future state through rAF
var paint = function(rAF){ 'use strict';
return function paint(before) {
before();
return rAF(before), {
then: function (after) {
return rAF(rAF.bind(null, after)), this;
}
};
};
}(
self.requestAnimationFrame ||
self.webkitRequestAnimationFrame ||
self.mozRequestAnimationFrame ||
self.oRequestAnimationFrame ||
self.msRequestAnimationFrame ||
function(fn) { setTimeout(fn, 1000 / 60); }
);
@WebReflection
Copy link
Author

WebReflection commented Feb 10, 2018

example

var style = document.body.appendChild(document.createElement('div')).style;
style.cssText = 'width:10px;height:10px;background:#000;transition:all .3s';

paint(() => style.transform = 'translateX(100px)')
  .then(() => style.transform = 'translateX(50px)');

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