JSFiddle - React, Tailwind, and code Playground
by Michael Bazos
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.js"></script>
<div ng-app="myApp" ng-controller="WordsController">
<div class="rotator">
<p>{{sentence.static}}</p>
<text-rotator options="sentence.options"></text-rotator>
</div>
</div>
CSS
@import url(http://fonts.googleapis.com/css?family=Open+Sans:600);
body {
font-family: 'Open Sans', sans-serif;
font-weight: 600;
font-size: 40px;
}
.text {
position: absolute;
width: 450px;
left: 50%;
margin-left: -225px;
height: 40px;
top: 50%;
margin-top: -20px;
}
p {
display: inline-block;
vertical-align: top;
margin: 0;
}
.word {
position: absolute;
width: 220px;
opacity: 0;
}
.letter {
display: inline-block;
position: relative;
float: left;
transform: translateZ(25px);
transform-origin: 50% 50% 25px;
}
.letter.out {
transform: rotateX(90deg);
transition: transform 0.32s cubic-bezier(0.55, 0.055, 0.675, 0.19);
}
.letter.behind {
transform: rotateX(-90deg);
}
.letter.in {
transform: rotateX(0deg);
transition: transform 0.38s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.wisteria {
color: #8e44ad;
}
.belize {
color: #2980b9;
}
.pomegranate {
color: #c0392b;
}
.green {
color: #16a085;
}
.midnight {
color: #2c3e50;
}
JavaScript
angular.module('myApp', []);
angular.module('myApp').directive('textRotator', function () {
return {
restrict: 'E',
scope: {
options: '='
}
templateUrl: '<span class="word" ng-repeat="item in sentence.options">{{item}}</span>',
link: function (scope, element, attrs) {
}
}
});
angular.module('myApp').controller('WordsController', function ($scope, $timeout) {
$scope.sentence = {static: 'Nachos are '};
// Simulating async call
$timeout(function () {}, 3000).then(function () {
$scope.sentence.options = ['tasty', 'wonderful', 'fancy', 'beautiful', 'cheap'];
})
});