Advertisement
menjaj01

Untitled

Nov 26th, 2024
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.57 KB | None | 0 0
  1. <div class="decoding">
  2. <div class="decode-text">
  3.     <div class="text-animation">D</div>
  4.     <div class="text-animation">O</div>
  5.     <div class="space"></div>
  6.  
  7.     <div class="text-animation">Y</div>
  8.     <div class="text-animation">O</div>
  9.     <div class="text-animation">U</div>
  10.     <div class="space"></div>
  11.  
  12.     <div class="text-animation">D</div>
  13.     <div class="text-animation">A</div>
  14.     <div class="text-animation">R</div>
  15.     <div class="text-animation">E</div>
  16.     <div class="space"></div>
  17.  
  18.     <div class="text-animation">T</div>
  19.     <div class="text-animation">A</div>
  20.     <div class="text-animation">K</div>
  21.     <div class="text-animation">E</div>
  22.     <div class="space"></div>
  23.  
  24.     <div class="text-animation">O</div>
  25.     <div class="text-animation">N</div>
  26.     <div class="space"></div>
  27.  
  28.     <div class="text-animation">T</div>
  29.     <div class="text-animation">H</div>
  30.     <div class="text-animation">E</div>
  31.     <div class="space"></div>
  32.  
  33.     <div class="text-animation">C</div>
  34.     <div class="text-animation">H</div>
  35.     <div class="text-animation">A</div>
  36.     <div class="text-animation">L</div>
  37.     <div class="text-animation">L</div>
  38.     <div class="text-animation">E</div>
  39.     <div class="text-animation">N</div>
  40.     <div class="text-animation">G</div>
  41.     <div class="text-animation">E</div>
  42.     <div class="text-animation">.</div>
  43.     <div class="text-animation">.</div>
  44.     <div class="text-animation">?</div>
  45. </div>
  46.  
  47. <p>
  48. 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.
  49. <p>
  50. <div>
  51.  
  52. <style>
  53.             @font-face {
  54.                 font-family: 'Traveling_Typewriter';
  55.                 src: url(Fonts/TravelingTypewriter.ttf) format('truetype');
  56.             }
  57.  
  58. .decoding {
  59.   font-family: 'Traveling_Typewriter', monospace;
  60.  
  61.   align-items: center;
  62. }
  63.  
  64. p {
  65.    width: 80vw;
  66.    text-align: center;
  67.    margin: 50px auto;
  68.    font-size: 18px;
  69. }
  70.  
  71. .decode-text {
  72.   width: 100%;
  73.   font-size: 35px;
  74.   text-align: center;
  75. }
  76.  
  77. .space {
  78.   display: inline-block;
  79.   width: 10px;
  80. }
  81.  
  82. .text-animation {
  83.   display: inline-block;
  84.   position: relative;
  85.   color: transparent;
  86.   text-transform: uppercase;
  87. }
  88. .text-animation:before {
  89.   content: "";
  90.   color: #EF9821;
  91.   position: absolute;
  92.   top: 50%;
  93.   left: 50%;
  94.   background: #ffffff;
  95.   width: 0;
  96.   height: 1.2em;
  97.   -webkit-transform: translate(-50%, -55%);
  98.   -ms-transform: translate(-50%, -55%);
  99.   transform: translate(-50%, -55%);
  100. }
  101. .text-animation.state-1:before {
  102.   width: 1px;
  103. }
  104. .text-animation.state-2:before {
  105.   width: 0.9em;
  106. }
  107. .text-animation.state-3 {
  108.   color: #EF9821;
  109. }
  110. .text-animation.state-3:before {
  111.   width: 0;
  112. }
  113.  
  114. </style>
  115.  
  116. <script>
  117. function decodeText(){
  118.     var text = document.getElementsByClassName('decode-text')[0];
  119.     // debug with
  120.     // console.log(text, text.children.length);
  121.  
  122.     // assign the placeholder array its places
  123.     var state = [];
  124.     for(var i = 0, j = text.children.length; i < j; i++ ){
  125.        text.children[i].classList.remove('state-1','state-2','state-3');
  126.        state[i] = i;
  127.    }
  128.  
  129.    // shuffle the array to get new sequences each time
  130.    var shuffled = shuffle(state);
  131.  
  132.    for(var i = 0, j = shuffled.length; i < j; i++ ){
  133.        var child = text.children[shuffled[i]];
  134.        classes = child.classList;
  135.  
  136.        // fire the first one at random times
  137.        var state1Time = Math.round( Math.random() * (2000 - 300) ) + 50;
  138.        if(classes.contains('text-animation')){
  139.            setTimeout(firstStages.bind(null, child), state1Time);
  140.        }
  141.    }
  142. }
  143.  
  144. // send the node for later .state changes
  145. function firstStages(child){
  146.    if( child.classList.contains('state-2') ){  
  147.        child.classList.add('state-3');
  148.    } else if( child.classList.contains('state-1') ){
  149.        child.classList.add('state-2')
  150.    } else if( !child.classList.contains('state-1') ){
  151.        child.classList.add('state-1');
  152.        setTimeout(secondStages.bind(null, child), 100);
  153.    }    
  154. }
  155. function secondStages(child){
  156.    if( child.classList.contains('state-1') ){
  157.        child.classList.add('state-2')
  158.        setTimeout(thirdStages.bind(null, child), 100);
  159.    }
  160.    else if( !child.classList.contains('state-1') )
  161.    {
  162.        child.classList.add('state-1')
  163.    }
  164. }
  165. function thirdStages(child){
  166.    if( child.classList.contains('state-2') ){
  167.        child.classList.add('state-3')
  168.    }
  169. }
  170.  
  171. function shuffle(array) {
  172.    var currentIndex = array.length, temporaryValue, randomIndex;
  173.  
  174.    // While there remain elements to shuffle...
  175.    while (0 !== currentIndex) {
  176.        // Pick a remaining element...
  177.        randomIndex = Math.floor(Math.random() * currentIndex);
  178.        currentIndex -= 1;
  179.  
  180.        // And swap it with the current element.
  181.        temporaryValue = array[currentIndex];
  182.        array[currentIndex] = array[randomIndex];
  183.        array[randomIndex] = temporaryValue;
  184.    }
  185.    return array;
  186. }
  187.  
  188.  
  189. // Demo only stuff
  190. decodeText();
  191.  
  192. // beware: refresh button can overlap this timer and cause state mixups
  193. setInterval(function(){ decodeText(); }, 5000);
  194.  
  195. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement