vinz.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. function scrollText(cont_id, text, options = {}){
  2. const opt = Object.assign({
  3. letter_width: 30,
  4. letter_height: 50,
  5. background_color: 'transparent',
  6. text_color: '#30f030',
  7. movement_increment: 3,
  8. interval_increment: 5,
  9. random_color: false,
  10. custom_color: false,
  11. final_color: false,
  12. initial_position_range: {
  13. min: -300,
  14. max: 300
  15. },
  16. change_letter_offset: 5
  17. }, options);
  18. const basic_colors = [
  19. '#ff0000',
  20. '#ffff00',
  21. '#00ff00',
  22. '#00ffff',
  23. '#0000ff',
  24. '#ff00ff',
  25. ];
  26. var scrollText_offsets = [];
  27. function randomInt(min,max){
  28. return Math.floor(Math.random()*(max-min+1)+min);
  29. }
  30. function randomChar(){
  31. const charlist = 'qazxswedcvfrtgbnhyujmkiolp1234567890_';
  32. return charlist[randomInt(0, charlist.length-1)];
  33. }
  34. function intToHex(i) {
  35. let hex = Number(i).toString(16);
  36. if (hex.length < 2) {
  37. hex = "0" + hex;
  38. }
  39. return hex;
  40. }
  41. function upColor(elem, start, step, random, colors){
  42. let newColor;
  43. if(random){
  44. if(colors){
  45. if(!Array.isArray(colors)) colors = basic_colors;
  46. newColor = colors[randomInt(0,colors.length-1)];
  47. }else{
  48. newColor = '#' + intToHex(randomInt(0,255)) + intToHex(randomInt(0,255)) + intToHex(randomInt(0,255));
  49. }
  50. }else{
  51. newColor = opt.text_color;
  52. }
  53. elem.style.color = newColor + '' + intToHex(255 - (Math.round( (255*step)/start) ));
  54. }
  55. function move(i) {
  56. let elem = document.getElementById('scrolltext_letter_part_' + i);
  57. let start = scrollText_offsets[i];
  58. let step;
  59. if(start>0){
  60. step = Math.abs(Math.round( (start+1) / opt.movement_increment ));
  61. }else if(start<0){
  62. step = Math.abs(Math.round( (start-1) / opt.movement_increment ));
  63. }
  64. let start_step = step;
  65. function frame() {
  66. if(start > 0){
  67. start -= opt.movement_increment;
  68. if(start<0)start = 0;
  69. }else{
  70. start += opt.movement_increment;
  71. if(start>0) start = 0;
  72. }
  73. step--;
  74. elem.style.left = start + 'px';
  75. upColor(elem, start_step, step, opt.random_color, opt.custom_color);
  76. if (start == 0){
  77. clearInterval(scrolltext_intervall_id);
  78. elem.innerHTML = text[i];
  79. elem.style.zIndex = 200;
  80. if(opt.final_color){
  81. elem.style.color = opt.final_color;
  82. }else{
  83. /*fix alla buona quando la trasparenza non è a 1*/
  84. let nv = elem.style.color.split(',');
  85. if(nv.length>3){
  86. nv[0] = nv[0].slice(nv[0].indexOf('(') + 1).trim();
  87. elem.style.color = 'rgb(' + nv[0] + ',' + nv[1] + ',' + nv[2] + ')';
  88. }
  89. }
  90. }else{
  91. if(start % opt.change_letter_offset == 0)
  92. elem.innerHTML = randomChar();
  93. }
  94. }
  95. var scrolltext_intervall_id = setInterval(frame, opt.interval_increment);
  96. }
  97. let cont = document.getElementById(cont_id);
  98. let html = '';
  99. for (let i = 0, l = text.length; i < l; i++) {
  100. scrollText_offsets[i] = randomInt(opt.initial_position_range.min, opt.initial_position_range.max);
  101. html += '<div class="scrolltext_letter" id="scrolltext_letter_part_' + i + '" style="'
  102. + 'color: ' + opt.text_color + '00; '
  103. + 'width: ' + opt.letter_width + 'px; '
  104. + 'height: ' + opt.letter_height + 'px; '
  105. + 'font-size: ' + (opt.letter_height - 10) + 'px; '
  106. + 'left: ' + scrollText_offsets[i] + 'px; '
  107. + '">' + randomChar() + '</div>';
  108. }
  109. cont.innerHTML = '<div class="scrolltext_container" style="'
  110. + 'background-color: ' + opt.background_color + '; '
  111. + 'height: ' + opt.letter_height + 'px; '
  112. + '">' + html + '</div>';
  113. setTimeout(function(){
  114. for (let i = 0; i < text.length; i++) {
  115. move(i);
  116. }
  117. }, 200);
  118. }
  119. // const test = {
  120. // v1: function(){
  121. // scrollText('text_header', 'Hacklab_', {
  122. // movement_increment: 1,
  123. // interval_increment: 10,
  124. // });
  125. // },
  126. // v2: function(){
  127. // scrollText('text_header', 'Hacklab_', {
  128. // initial_position_range: {
  129. // min: -500,
  130. // max: 500
  131. // },
  132. // text_color: '#ff3a3a',
  133. // change_letter_offset: 7
  134. // });
  135. // },
  136. // v3: function(){
  137. // scrollText('text_header', 'Hacklab_', {
  138. // initial_position_range: {
  139. // min: 0,
  140. // max: 500
  141. // },
  142. // final_color: '#00ffff'
  143. // });
  144. // },
  145. // v4: function(){
  146. // scrollText('text_header', 'Hacklab_', {
  147. // random_color: true
  148. // });
  149. // },
  150. // v5: function(){
  151. // scrollText('text_header', 'Hacklab_', {
  152. // random_color: true,
  153. // custom_color: true
  154. // });
  155. // },
  156. // v6: function(){
  157. // scrollText('text_header', 'Hacklab_', {
  158. // random_color: true,
  159. // custom_color: ['#ff0000','#0000ff']
  160. // });
  161. // },
  162. // v7: function(){
  163. // scrollText('text_header', 'Hacklab_', {
  164. // random_color: true,
  165. // custom_color: true,
  166. // final_color: '#ff0000'
  167. // });
  168. // },
  169. // };
  170. scrollText('text_header', 'underscore hacklab');
  171. console.error('son qua?!?')