Created
January 29, 2014 18:59
-
-
Save stefbowerman/8694534 to your computer and use it in GitHub Desktop.
MySpace Cursor Trail. Used originally to trail a balloon looking cursor with 3 different sized bubble images.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomFromInterval(from,to) | |
{ | |
return Math.floor(Math.random()*(to-from+1)+from); | |
} | |
function cursorTrail(e){ | |
var i = randomFromInterval(1, 3), | |
fadeOutTime = randomFromInterval(100, 200), | |
top = e.pageY - randomFromInterval(15, 20), | |
left = e.pageX- randomFromInterval(15, 20), | |
animateTop = randomFromInterval(5, 10), | |
animateLeft = randomFromInterval(5, 10); | |
$mouseTrail = $('<img src="assets/images/mousetrail-' + i + '.png">') | |
$mouseTrail.css({ | |
'position':'absolute', | |
'opactiy':'0.5', | |
'top':top, | |
'left':left | |
}) | |
.prependTo($('body')) | |
.animate({ | |
left: "-="+animateLeft+"px", | |
top: "-="+animateTop+"px", | |
opacity: "-=0.5", | |
}, fadeOutTime, function(){ | |
$(this).remove(); | |
}); | |
} | |
$('body').mousemove( function(e){ | |
if(!$(e.target).is('a')){ | |
cursorTrail(e); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment