Senin, 24 April 2017

CARA MEMBUAT TULISAN BERGERAK MENGIKUTI KURSOR DI BLOG

CARA MEMBUAT TULISAN BERGERAK MENGIKUTI KURSOR DI BLOG
ASSALAMUALAIKUM WR WB.

Pada kesempatan kali ini saya akan memposting info mengenai cara membuat tulisan bergerak mengikuti kursor ,ini source codenya:




  1. <style type='text/css'>
  2.     #outerCircleText {
  3.     font-style: italic;
  4.     font-weight: normal;
  5.     font-family: jokerman;
  6.     color: blue;

  7.     position: absolute;top: 0;left: 0;z-index: 3000;cursor: default;}
  8.     #outerCircleText div {position: relative;}
  9.     #outerCircleText div div {position: absolute;top: 0;left: 0;text-align: center;}

  10.     </style>
  11.     <script type='text/javascript'>
  12.     //<![CDATA[

  13.     ;(function(){
  14.     // =====Pengaturan Dimulai=====//
  15.     // Masukkan kalimat yang diinginkan (QUOTED STRING)
  16.     var msg = "WELCOME TO BELAJAR BARENG ANDI.N";

  17.     // Set font's style size for calculating dimensions
  18.     // Set to number of desired pixels font size (decimal and negative numbers not allowed)
  19.     var size = 15;

  20.     // Set both to 1 for plain circle, set one of them to 2 for oval
  21.     // Other numbers & decimals can have interesting effects, keep these low (0 to 3)
  22.     var circleY = 0.75; var circleX = 2;

  23.     // The larger this divisor, the smaller the spaces between letters
  24.     // (decimals allowed, not negative numbers)
  25.     var letter_spacing = 5;

  26.     // The larger this multiplier, the bigger the circle/oval
  27.     // (decimals allowed, not negative numbers, some rounding is applied)
  28.     var diameter = 5;

  29.     // Rotation speed, set it negative if you want it to spin clockwise (decimals allowed)
  30.     var rotation = 0.2;

  31.     // This is not the rotation speed, its the reaction speed, keep low!
  32.     // Set this to 1 or a decimal less than one (decimals allowed, not negative numbers)
  33.     var speed = 0.3;

  34.     // =====Pengaturan Selesai=====//

  35.     if (!window.addEventListener && !window.attachEvent || !document.createElement) return;

  36.     msg = msg.split('');
  37.     var n = msg.length - 1, a = Math.round(size * diameter * 0.208333), currStep = 20,
  38.     ymouse = a * circleY + 20, xmouse = a * circleX + 20, y = [], x = [], Y = [], X = [],
  39.     o = document.createElement('div'), oi = document.createElement('div'),
  40.     b = document.compatMode && document.compatMode != "BackCompat"? document.documentElement :

  41.     document.body,

  42.     mouse = function(e){
  43.     e = e || window.event;
  44.     ymouse = !isNaN(e.pageY)? e.pageY : e.clientY; // y-position
  45.     xmouse = !isNaN(e.pageX)? e.pageX : e.clientX; // x-position
  46.     },

  47.     makecircle = function(){ // rotation/positioning
  48.     if(init.nopy){
  49.     o.style.top = (b || document.body).scrollTop + 'px';
  50.     o.style.left = (b || document.body).scrollLeft + 'px';
  51.     };
  52.     currStep -= rotation;
  53.     for (var d, i = n; i > -1; --i){ // makes the circle
  54.     d = document.getElementById('iemsg' + i).style;
  55.     d.top = Math.round(y[i] + a * Math.sin((currStep + i) / letter_spacing) * circleY - 15) +

  56.     'px';
  57.     d.left = Math.round(x[i] + a * Math.cos((currStep + i) / letter_spacing) * circleX) + 'px';
  58.     };
  59.     },

  60.     drag = function(){ // makes the resistance
  61.     y[0] = Y[0] += (ymouse - Y[0]) * speed;
  62.     x[0] = X[0] += (xmouse - 20 - X[0]) * speed;
  63.     for (var i = n; i > 0; --i){
  64.     y[i] = Y[i] += (y[i-1] - Y[i]) * speed;
  65.     x[i] = X[i] += (x[i-1] - X[i]) * speed;
  66.     };
  67.     makecircle();
  68.     },

  69.     init = function(){ // appends message divs, & sets initial values for positioning arrays
  70.     if(!isNaN(window.pageYOffset)){
  71.     ymouse += window.pageYOffset;
  72.     xmouse += window.pageXOffset;
  73.     } else init.nopy = true;
  74.     for (var d, i = n; i > -1; --i){
  75.     d = document.createElement('div'); d.id = 'iemsg' + i;
  76.     d.style.height = d.style.width = a + 'px';
  77.     d.appendChild(document.createTextNode(msg[i]));
  78.     oi.appendChild(d); y[i] = x[i] = Y[i] = X[i] = 0;
  79.     };
  80.     o.appendChild(oi); document.body.appendChild(o);
  81.     setInterval(drag, 25);
  82.     },

  83.     ascroll = function(){
  84.     ymouse += window.pageYOffset;
  85.     xmouse += window.pageXOffset;
  86.     window.removeEventListener('scroll', ascroll, false);
  87.     };

  88.     o.id = 'outerCircleText'; o.style.fontSize = size + 'px';

  89.     if (window.addEventListener){
  90.     window.addEventListener('load', init, false);
  91.     document.addEventListener('mouseover', mouse, false);
  92.     document.addEventListener('mousemove', mouse, false);
  93.     if (/Apple/.test(navigator.vendor))
  94.     window.addEventListener('scroll', ascroll, false);
  95.     }
  96.     else if (window.attachEvent){
  97.     window.attachEvent('onload', init);
  98.     document.attachEvent('onmousemove', mouse);
  99.     };

  100.     })();
  101.     //]]>
  102.     </script>                                                       
ini contoh tampilannya:

Tidak ada komentar:

Posting Komentar