var DOMElement = famous.domRenderables.DOMElement;
var Transitionable = famous.transitions.Transitionable;
var FamousEngine = famous.core.FamousEngine;
var Node = famous.core.Node;
// Create scene.
var scene = FamousEngine.createScene();
FamousEngine.init();
var boxNode = scene.addChild();
boxNode.setSizeMode('absolute', 'absolute')
.setAbsoluteSize(100, 100)
.setPosition(0,0,0);
boxNode.addUIEvent('click');
var boxElement = new DOMElement(boxNode);
boxElement.setProperty('background-color', 'lightblue');
boxElement.setContent('Click Me');
var clock = FamousEngine.getClock();
var boxTransitionable = new Transitionable(0);
var myComponent = {
id: null,
node: null,
onMount: function (node) {
this.id = node.addComponent(this);
this.node = node;
},
onReceive(type, event) {
if (type === 'click') {
this.node.requestUpdate(this.id);
boxTransitionable.from(0).to(300, 'outBounce', 2000, done);
boxTransitionable.set(0, { duration: 2000, curve: 'outBounce' }, done);
}
},
onUpdate: function() {
if (boxTransitionable.isActive()) {
var xpos = boxTransitionable.get();
console.log(xpos, boxTransitionable.isActive());
this.node.setPosition(xpos,0,0);
this.node.requestUpdateOnNextTick(this.id);
}
}
};
boxNode.addComponent(myComponent);
// Callback is specified but it never successfully runs.
function done() {
console.log('at the end');
}
html, body {
width: 100%;
height: 100%;
margin: 0px;
padding: 0px;
}
body {
position: absolute;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-font-smoothing: antialiased;
-webkit-tap-highlight-color: transparent;
background-color: black;
-webkit-perspective: 0;
perspective: none;
overflow: hidden;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Famous0.6.2</title>
<link rel="icon" href="favicon.ico?v=1" type="image/x-icon">
<meta name="description" content="Transition callback Famous@0.6.2">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://code.famo.us/famous/0.6.2/famous.min.js"></script>
</head>
<body>
</body>
</html>