Created
October 13, 2014 08:49
-
-
Save jsm/469fa0c4f3769f866018 to your computer and use it in GitHub Desktop.
The Jessie Effect
This file contains hidden or 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
jQuery( document ).ready(function( $ ) { | |
var image = 'https://s3-us-west-1.amazonaws.com/static.sanmiguel.je/cuttlefish.png' | |
$('body').append('<img id="jessieEffect" src="' + image + '" style="visibility:hidden;position:absolute;z-index:10000;">'); | |
jessieImage = $('#jessieEffect'); | |
jessieImage.css('visibility', 'visible'); | |
var topOffset; | |
function reset() { | |
jessieImage.css('left', $(window).width()); | |
$('#jessieEffect').css('top', parseInt(($(window).height() - $('#jessieEffect').height()) * Math.random())); | |
topOffset = parseInt(Math.random() * 5) - 1; | |
} | |
reset(); | |
setInterval(function() { | |
if ( parseInt($('#jessieEffect').css('left')) <= 0 - parseInt($('#jessieEffect').width()) ) { | |
reset(); | |
} | |
$('#jessieEffect').css('left', parseInt($('#jessieEffect').css('left')) - 1); | |
}, 3); | |
setInterval(function() { | |
if ( parseInt($('#jessieEffect').css('top')) >= parseInt($(window).height()) - parseInt($('#jessieEffect').height()) || parseInt($('#jessieEffect').css('top')) <= 0 ) { | |
topOffset = topOffset * -1; | |
} | |
$('#jessieEffect').css('top', parseInt($('#jessieEffect').css('top')) + topOffset); | |
}, 15); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment