Advertisement
solielios

Circle text cursor trail ♡

Sep 20th, 2021
571
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. <style type="text/css">
  2.  
  3. /* Circle Text Styles */
  4.  
  5. #outerCircleText {
  6.  
  7. /* Optional - DO NOT SET FONT-SIZE HERE, SET IT IN THE SCRIPT */
  8.  
  9. font-style: italic;
  10.  
  11. font-weight: bold;
  12.  
  13. font-family: inherit;
  14.  
  15. color: #000;
  16.  
  17. /* End Optional */
  18.  
  19.  
  20.  
  21. /* Start Required - Do Not Edit */
  22.  
  23. position: absolute;top: 0;left: 0;z-index: 3000;cursor: default;}
  24.  
  25. #outerCircleText div {position: relative;}
  26.  
  27. #outerCircleText div div {position: absolute;top: 0;left: 0;text-align: center;}
  28.  
  29. /* End Required */
  30.  
  31. /* End Circle Text Styles */
  32.  
  33. </style><script type="text/javascript">
  34.  
  35.  
  36.  
  37. /* Circling text trail- Tim Tilton
  38.  
  39. Website: http://www.tempermedia.com/
  40.  
  41. Visit: http://www.dynamicdrive.com/ for Original Source and tons of scripts
  42.  
  43. Modified Here for more flexibility and modern browser support
  44.  
  45. Modifications as first seen in http://www.dynamicdrive.com/forums/
  46.  
  47. username:jscheuer1 - This notice must remain for legal use
  48.  
  49. */
  50.  
  51.  
  52.  
  53. ;(function(){
  54.  
  55.  
  56.  
  57. // Your message here (QUOTED STRING)
  58.  
  59. var msg = "Put your message here... but try not putting too much...";
  60.  
  61.  
  62.  
  63. /* THE REST OF THE EDITABLE VALUES BELOW ARE ALL UNQUOTED NUMBERS */
  64.  
  65.  
  66.  
  67. // Set font's style size for calculating dimensions
  68.  
  69. // Set to number of desired pixels font size (decimal and negative numbers not allowed)
  70.  
  71. var size = 14;
  72.  
  73.  
  74.  
  75. // Set both to 1 for plain circle, set one of them to 2 for oval
  76.  
  77. // Other numbers & decimals can have interesting effects, keep these low (0 to 3)
  78.  
  79. var circleY = 0.75; var circleX = 2;
  80.  
  81.  
  82.  
  83. // The larger this divisor, the smaller the spaces between letters
  84.  
  85. // (decimals allowed, not negative numbers)
  86.  
  87. var letter_spacing = 6;
  88.  
  89.  
  90.  
  91. // The larger this multiplier, the bigger the circle/oval
  92.  
  93. // (decimals allowed, not negative numbers, some rounding is applied)
  94.  
  95. var diameter = 8;
  96.  
  97.  
  98.  
  99. // Rotation speed, set it negative if you want it to spin clockwise (decimals allowed)
  100.  
  101. var rotation = 0.4;
  102.  
  103.  
  104.  
  105. // This is not the rotation speed, its the reaction speed, keep low!
  106.  
  107. // Set this to 1 or a decimal less than one (decimals allowed, not negative numbers)
  108.  
  109. var speed = 0.3;
  110.  
  111.  
  112.  
  113. ////////////////////// Stop Editing //////////////////////
  114.  
  115.  
  116.  
  117. if (!window.addEventListener && !window.attachEvent || !document.createElement) return;
  118.  
  119.  
  120.  
  121. msg = msg.split('');
  122.  
  123. var n = msg.length - 1, a = Math.round(size * diameter * 0.208333), currStep = 20,
  124.  
  125. ymouse = a * circleY + 20, xmouse = a * circleX + 20, y = [], x = [], Y = [], X = [],
  126.  
  127. o = document.createElement('div'), oi = document.createElement('div'),
  128.  
  129. b = document.compatMode && document.compatMode != "BackCompat"? document.documentElement : document.body,
  130.  
  131.  
  132.  
  133. mouse = function(e){
  134.  
  135. e = e || window.event;
  136.  
  137. ymouse = !isNaN(e.pageY)? e.pageY : e.clientY; // y-position
  138.  
  139. xmouse = !isNaN(e.pageX)? e.pageX : e.clientX; // x-position
  140.  
  141. },
  142.  
  143.  
  144.  
  145. makecircle = function(){ // rotation/positioning
  146.  
  147. if(init.nopy){
  148.  
  149. o.style.top = (b || document.body).scrollTop + 'px';
  150.  
  151. o.style.left = (b || document.body).scrollLeft + 'px';
  152.  
  153. };
  154.  
  155. currStep -= rotation;
  156.  
  157. for (var d, i = n; i > -1; --i){ // makes the circle
  158.  
  159. d = document.getElementById('iemsg' + i).style;
  160.  
  161. d.top = Math.round(y[i] + a * Math.sin((currStep + i) / letter_spacing) * circleY - 15) + 'px';
  162.  
  163. d.left = Math.round(x[i] + a * Math.cos((currStep + i) / letter_spacing) * circleX) + 'px';
  164.  
  165. };
  166.  
  167. },
  168.  
  169.  
  170.  
  171. drag = function(){ // makes the resistance
  172.  
  173. y[0] = Y[0] += (ymouse - Y[0]) * speed;
  174.  
  175. x[0] = X[0] += (xmouse - 20 - X[0]) * speed;
  176.  
  177. for (var i = n; i > 0; --i){
  178.  
  179. y[i] = Y[i] += (y[i-1] - Y[i]) * speed;
  180.  
  181. x[i] = X[i] += (x[i-1] - X[i]) * speed;
  182.  
  183. };
  184.  
  185. makecircle();
  186.  
  187. },
  188.  
  189.  
  190.  
  191. init = function(){ // appends message divs, & sets initial values for positioning arrays
  192.  
  193. if(!isNaN(window.pageYOffset)){
  194.  
  195. ymouse += window.pageYOffset;
  196.  
  197. xmouse += window.pageXOffset;
  198.  
  199. } else init.nopy = true;
  200.  
  201. for (var d, i = n; i > -1; --i){
  202.  
  203. d = document.createElement('div'); d.id = 'iemsg' + i;
  204.  
  205. d.style.height = d.style.width = a + 'px';
  206.  
  207. d.appendChild(document.createTextNode(msg[i]));
  208.  
  209. oi.appendChild(d); y[i] = x[i] = Y[i] = X[i] = 0;
  210.  
  211. };
  212.  
  213. o.appendChild(oi); document.body.appendChild(o);
  214.  
  215. setInterval(drag, 25);
  216.  
  217. },
  218.  
  219.  
  220.  
  221. ascroll = function(){
  222.  
  223. ymouse += window.pageYOffset;
  224.  
  225. xmouse += window.pageXOffset;
  226.  
  227. window.removeEventListener('scroll', ascroll, false);
  228.  
  229. };
  230.  
  231.  
  232.  
  233. o.id = 'outerCircleText'; o.style.fontSize = size + 'px';
  234.  
  235.  
  236.  
  237. if (window.addEventListener){
  238.  
  239. window.addEventListener('load', init, false);
  240.  
  241. document.addEventListener('mouseover', mouse, false);
  242.  
  243. document.addEventListener('mousemove', mouse, false);
  244.  
  245. if (/Apple/.test(navigator.vendor))
  246.  
  247. window.addEventListener('scroll', ascroll, false);
  248.  
  249. }
  250.  
  251. else if (window.attachEvent){
  252.  
  253. window.attachEvent('onload', init);
  254.  
  255. document.attachEvent('onmousemove', mouse);
  256.  
  257. };
  258.  
  259.  
  260.  
  261. })();
  262.  
  263.  
  264.  
  265. </script>
  266.  
  267.  
  268.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement