4umi.com/web/javascript/mousetail

It 's all in the tail

Mousetail Javascript

This is a story about a mouse and his devoted followers the words. For everywhere that the mouse went, the words were sure to follow.

Examine the script.

var d = window.document, f = d.forms.f, l = [];

function getmouse( e ) {
 e = e || window.event || {};
 var w = getwindow(), x, y;
 if( typeof e.pageX==='number' ) {
  x = e.pageX;
  y = e.pageY;
 } else {
  x = e.x + w.l;
  y = e.y + w.t;
 }
 return { x: x, y: y };
}

function makeletters() {
 if( d.createElement ) {
  var s = f&&f.t.value||'Welcome to the machine', i = s.length,
   o = d.createElement( 'div' ), p, q = o.style;
  o.insertBefore( d.createTextNode( ' ' ), null );
  q.position = 'absolute';
  q.color = 'darkred';
  q.font = 'bold 120% Arial, Helvetica, sans-serif';
  while( i-- ) {
   p = o.cloneNode( true );
   p.lastChild.nodeValue = s.charAt( i );
   l[i] = d.body.insertBefore( p, null );
  }
 }
}

function mm( e ) {
 e = e || window.event || {};
 if( l ) {
  var i = l.length, v = getmouse( e );
  while( i-- ) {
   l[i].style.top = v.y + 12 + 'px';
   l[i].style.left = v.x + i*12 + 'px';
  }
 }
}

makeletters();
d.onmousemove = mm;