zhansitos

tracklist typewriter

Oct 25th, 2022 (edited)
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <!-- player crd co code by femcel2006 (me) -->
  2.  
  3. <h3>
  4.  
  5. <a role="link" aria-disabled="true" class="typewrite" data-period="10000" data-type='[ "Picture in my mind", "Color Drive", "Yellow Cab", "Wondrous Place" ]'> <span class="wrap"></span>
  6.  
  7. </a>
  8.  
  9. </h3>
  10.  
  11.  
  12. <script>
  13.  
  14. var TxtType = function(el, toRotate, period) {
  15.  
  16. this.toRotate = toRotate;
  17.  
  18. this.el = el;
  19.  
  20. this.loopNum = 0;
  21.  
  22. this.period = parseInt(period, 10) || 2000;
  23.  
  24. this.txt = '';
  25.  
  26. this.tick();
  27.  
  28. this.isDeleting = false;
  29.  
  30. };
  31.  
  32.  
  33. TxtType.prototype.tick = function() {
  34.  
  35. var i = this.loopNum % this.toRotate.length;
  36.  
  37. var fullTxt = this.toRotate[i];
  38.  
  39.  
  40. if (this.isDeleting) {
  41.  
  42. this.txt = fullTxt.substring(0, this.txt.length - 1);
  43.  
  44. } else {
  45.  
  46. this.txt = fullTxt.substring(0, this.txt.length + 1);
  47.  
  48. }
  49.  
  50.  
  51. this.el.innerHTML = '<span class="wrap">'+this.txt+'</span>';
  52.  
  53.  
  54. var that = this;
  55.  
  56. var delta = 200 - Math.random() * 100;
  57.  
  58.  
  59. if (this.isDeleting) { delta /= 2; }
  60.  
  61.  
  62. if (!this.isDeleting && this.txt === fullTxt) {
  63.  
  64. delta = this.period;
  65.  
  66. this.isDeleting = true;
  67.  
  68. } else if (this.isDeleting && this.txt === '') {
  69.  
  70. this.isDeleting = false;
  71.  
  72. this.loopNum++;
  73.  
  74. delta = 500;
  75.  
  76. }
  77.  
  78.  
  79. setTimeout(function() {
  80.  
  81. that.tick();
  82.  
  83. }, delta);
  84.  
  85. };
  86.  
  87.  
  88. window.onload = function() {
  89.  
  90. var elements = document.getElementsByClassName('typewrite');
  91.  
  92. for (var i=0; i<elements.length; i++) {
  93.  
  94. var toRotate = elements[i].getAttribute('data-type');
  95.  
  96. var period = elements[i].getAttribute('data-period');
  97.  
  98. if (toRotate) {
  99.  
  100. new TxtType(elements[i], JSON.parse(toRotate), period);
  101.  
  102. }
  103.  
  104. }
  105.  
  106. // INJECT CSS
  107.  
  108. var css = document.createElement("style");
  109.  
  110. css.type = "text/css";
  111.  
  112. css.innerHTML = ".typewrite > .wrap { border-right: 0.08em solid #fff}";
  113.  
  114. document.body.appendChild(css);
  115.  
  116. };
  117.  
  118. </script>
  119.  
  120. <style>
  121.  
  122. h3 {
  123.  
  124. font-family:Pixelated MS Sans Serif;
  125.  
  126. font-size:1em;
  127.  
  128. padding:4px;
  129.  
  130. background: #000;
  131.  
  132. color:#fff;
  133.  
  134. text-align:right;
  135.  
  136. }
  137.  
  138. a{
  139.  
  140. color:#fff;
  141.  
  142. text-decoration: none; }
  143.  
  144. </style>
  145.  
  146.  
Advertisement
Add Comment
Please, Sign In to add comment