Creating a mouse trail effect
I'm just beginning to experiment with the "fun" side of JavaScript.
One thing I've noticed you could do is create an image/text that follows the
mouse around using JavaScript. It's a neat effect that once only existed inside
your OS, not your browser.
Here is the code I wrote that implements a mouse trail:
<div id="mousetrail" style="position:absolute"><img src="trail.gif"></div>
<script>
if (document.all)
trailcontainer=document.all.mousetrail.style
else if (document.getElementById)
trailcontainer=document.getElementById("mousetrail").style
else if (document.layers){
document.captureEvents(Event.MOUSEMOVE)
trailcontainer=document.layers.mousetrail
}
function followmouse(e){
trailcontainer.left= (document.all)? event.clientX+8 : e.x+8
trailcontainer.top=(document.all)? event.clientY+8 : e.y+8
}
document.onmousemove=followmouse
</script>
Just replace "trail.gif" with the image you wish to follow your
mouse.
You can get pretty carried away with fancying up your trail. My favorite script
archives devote an entire category to them. Check the WebAbstract
archive and Dynamic
Drive archive for inspiration.