How about something like that .... LIVE FIDDLE
HTML
<img src="http://www.birdsnways.com/imgs/blbd48rt.gif" id="picture" />
CSS
#picture{ position:absolute; }
Js
doNextPoint(); function doNextPoint(){ var maxX = $(window).width() - $('#picture').width(); var newX = rand(0, maxX); var maxY = ($(window).height()/2) - $('#picture').height(); var newY = rand(0, maxY); var speed = rand (1000, 3000); $('#picture').animate({ 'top': newY + 'px', 'left': newX + 'px' }, speed, function(){ doNextPoint(); }); } function rand (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; }
Dutchie432
source share