JSFiddle - React, Tailwind, and code Playground
by rich_harris
HTML
<main></main>
<script id='template' type='text/ractive'>
<button on-click='set("animating",true)' disabled='{{animating}}'>go</button>
<p>expected result: clicking 'go' should cause a box to appear and slide slowly across the screen, before disappearing</p>
{{#if animating}}
<div class='box' on-animend='set("animating",false)'></div>
{{/if}}
</script>
CSS
body {
font-family: 'Helvetica Neue', arial, sans-serif;
font-weight: 200;
color: #353535;
}
h1, h2, h3, h4, h5, h6 {
font-weight: 200;
}
.error {
color: #d00;
font-family: monospace;
}
.box {
position: absolute;
background-color: teal;
width: 100px;
height: 100px;
-webkit-animation: alternate 2s 1 slide linear;
animation: alternate 2s 1 slide linear;
}
@-webkit-keyframes slide {
0% {
left: 0;
}
100% {
left: 50%;
}
}
@keyframes slide {
0% {
left: 0;
}
100% {
left: 50%;
}
}
JavaScript
var ractive = new Ractive({
el: 'main',
template: '#template',
events: {
// cross-browser (well some of them) animationend event
animend: function ( node, callback ) {
function handler () {
callback({ node: node, original: event });
}
node.addEventListener( 'animationend', handler, false );
node.addEventListener( 'webkitAnimationEnd', handler, false );
return {
teardown: function () {
node.removeEventListener( 'animationend', handler, false );
node.removeEventListener( 'webkitAnimationEnd', handler, false );
}
};
}
}
});