Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="decoding">
- <div class="decode-text">
- <div class="text-animation">D</div>
- <div class="text-animation">O</div>
- <div class="space"></div>
- <div class="text-animation">Y</div>
- <div class="text-animation">O</div>
- <div class="text-animation">U</div>
- <div class="space"></div>
- <div class="text-animation">D</div>
- <div class="text-animation">A</div>
- <div class="text-animation">R</div>
- <div class="text-animation">E</div>
- <div class="space"></div>
- <div class="text-animation">T</div>
- <div class="text-animation">A</div>
- <div class="text-animation">K</div>
- <div class="text-animation">E</div>
- <div class="space"></div>
- <div class="text-animation">O</div>
- <div class="text-animation">N</div>
- <div class="space"></div>
- <div class="text-animation">T</div>
- <div class="text-animation">H</div>
- <div class="text-animation">E</div>
- <div class="space"></div>
- <div class="text-animation">C</div>
- <div class="text-animation">H</div>
- <div class="text-animation">A</div>
- <div class="text-animation">L</div>
- <div class="text-animation">L</div>
- <div class="text-animation">E</div>
- <div class="text-animation">N</div>
- <div class="text-animation">G</div>
- <div class="text-animation">E</div>
- <div class="text-animation">.</div>
- <div class="text-animation">.</div>
- <div class="text-animation">?</div>
- </div>
- <p>
- Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
- <p>
- <div>
- <style>
- @font-face {
- font-family: 'Traveling_Typewriter';
- src: url(Fonts/TravelingTypewriter.ttf) format('truetype');
- }
- .decoding {
- font-family: 'Traveling_Typewriter', monospace;
- align-items: center;
- }
- p {
- width: 80vw;
- text-align: center;
- margin: 50px auto;
- font-size: 18px;
- }
- .decode-text {
- width: 100%;
- font-size: 35px;
- text-align: center;
- }
- .space {
- display: inline-block;
- width: 10px;
- }
- .text-animation {
- display: inline-block;
- position: relative;
- color: transparent;
- text-transform: uppercase;
- }
- .text-animation:before {
- content: "";
- color: #EF9821;
- position: absolute;
- top: 50%;
- left: 50%;
- background: #ffffff;
- width: 0;
- height: 1.2em;
- -webkit-transform: translate(-50%, -55%);
- -ms-transform: translate(-50%, -55%);
- transform: translate(-50%, -55%);
- }
- .text-animation.state-1:before {
- width: 1px;
- }
- .text-animation.state-2:before {
- width: 0.9em;
- }
- .text-animation.state-3 {
- color: #EF9821;
- }
- .text-animation.state-3:before {
- width: 0;
- }
- </style>
- <script>
- function decodeText(){
- var text = document.getElementsByClassName('decode-text')[0];
- // debug with
- // console.log(text, text.children.length);
- // assign the placeholder array its places
- var state = [];
- for(var i = 0, j = text.children.length; i < j; i++ ){
- text.children[i].classList.remove('state-1','state-2','state-3');
- state[i] = i;
- }
- // shuffle the array to get new sequences each time
- var shuffled = shuffle(state);
- for(var i = 0, j = shuffled.length; i < j; i++ ){
- var child = text.children[shuffled[i]];
- classes = child.classList;
- // fire the first one at random times
- var state1Time = Math.round( Math.random() * (2000 - 300) ) + 50;
- if(classes.contains('text-animation')){
- setTimeout(firstStages.bind(null, child), state1Time);
- }
- }
- }
- // send the node for later .state changes
- function firstStages(child){
- if( child.classList.contains('state-2') ){
- child.classList.add('state-3');
- } else if( child.classList.contains('state-1') ){
- child.classList.add('state-2')
- } else if( !child.classList.contains('state-1') ){
- child.classList.add('state-1');
- setTimeout(secondStages.bind(null, child), 100);
- }
- }
- function secondStages(child){
- if( child.classList.contains('state-1') ){
- child.classList.add('state-2')
- setTimeout(thirdStages.bind(null, child), 100);
- }
- else if( !child.classList.contains('state-1') )
- {
- child.classList.add('state-1')
- }
- }
- function thirdStages(child){
- if( child.classList.contains('state-2') ){
- child.classList.add('state-3')
- }
- }
- function shuffle(array) {
- var currentIndex = array.length, temporaryValue, randomIndex;
- // While there remain elements to shuffle...
- while (0 !== currentIndex) {
- // Pick a remaining element...
- randomIndex = Math.floor(Math.random() * currentIndex);
- currentIndex -= 1;
- // And swap it with the current element.
- temporaryValue = array[currentIndex];
- array[currentIndex] = array[randomIndex];
- array[randomIndex] = temporaryValue;
- }
- return array;
- }
- // Demo only stuff
- decodeText();
- // beware: refresh button can overlap this timer and cause state mixups
- setInterval(function(){ decodeText(); }, 5000);
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement