JSFiddle - React, Tailwind, and code Playground
by devy indriyani
HTML
<div class="score">0</div>
<div class="stage"></div>
CSS
/*================================================
General
================================================*/
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
html,
body {
background-color: #000;
height: 100%;
}
body {
background: #222;
background: -webkit-radial-gradient(#333, #111);
background: radial-gradient(#333, #111);
background-position: center center;
background-repeat: no-repeat;
-webkit-background-size: cover;
background-size: cover;
color: #fff;
font: 100%/1.5 sans-serif;
overflow: hidden;
}
/*================================================
Score
================================================*/
.score {
color: rgba(255, 255, 255, 0.5);
font-size: 16px;
font-weight: bold;
padding-top: 5px;
text-align: center;
}
/*================================================
Stage
================================================*/
.stage {
bottom: 0;
left: 0;
margin: auto;
position: absolute;
right: 0;
top: 0;
z-index: 2;
}
/*================================================
Tiles
================================================*/
.tile {
background: rgba(0, 0, 0, 0.15);
position: absolute;
-webkit-transition-property:
background,
-webkit-box-shadow,
opacity,
-webkit-transform;
transition-property:
background,
box-shadow,
opacity,
transform
;
-webkit-transform: translateZ(0);
transform: translateZ(0);
-webkit-transition-duration: 3000ms;
transition-duration: 3000ms;
}
.tile:before {
bottom: 0;
content: '';
height: 0;
left: 0;
margin: auto;
opacity: 0;
position: absolute;
right: 0;
top: 0;
width: 0;
-webkit-transition: opacity 300ms;
transition: opacity 300ms;
}
.tile.path:before {
opacity: 1;
}
.tile.up:before {
border-bottom: 4px inset rgba(255, 255, 255, 0.15);
border-left: 4px solid transparent;
border-right: 4px solid transparent;
}
.tile.down:before {
...
JavaScript
/*================================================
Polyfill
================================================*/
(function(){ 'use strict';
/*================================================
Request Animation Frame
================================================*/
var lastTime = 0;
var vendors = [ 'webkit', 'moz' ];
for( var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x ) {
window.requestAnimationFrame = window[ vendors[ x ] + 'RequestAnimationFrame' ];
window.cancelAnimationFrame = window[ vendors[ x ] + 'CancelAnimationFrame' ] || window[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
}
if( !window.requestAnimationFrame ) {
window.requestAnimationFrame = function( callback, element ) {
var currTime = new Date().getTime();
var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
var id = window.setTimeout(
function() {
callback( currTime + timeToCall );
}, timeToCall );
lastTime = currTime + timeToCall;
return id;
}
}
if( !window.cancelAnimationFrame ) {
window.cancelAnimationFrame = function( id ) {
clearTimeout( id );
}
}
})();
/*================================================
DOM Manipulation
================================================*/
(function(){ 'use strict';
function hasClass( elem, className ) {
return new RegExp( ' ' + className + ' ' ).test( ' ' + elem.className + ' ' );
};
function addClass( elem, className ) {
if( !hasClass(elem, className ) ) {
elem.className += ' ' + className;
}
};
function removeClass( elem, className ) {
var newClass = ' ' + elem.className.replace( /[\t\r\n]/g, ' ' ) + ' ';
if( hasClass( elem, className ) ) {
while( newClass.indexOf(' ' + className + ' ' ) >= 0 ) {
newClass = newClass.replace( ' ' + className + ' ', ' ' );
}
elem.className = newClass.replace( /^\s+|\s+$/g, '' );
}
};
function...