Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var orangeFish = $("#fish1Id");
- var blueFish = $("#fish2Id");
- fishRandomMovement(orangeFish);
- fishRandomMovement(blueFish);
- function fishRandomMovement(IdRef){
- var tempSpeedLeft = (Math.random() < 0.5 ? -1 : 1) * 1 + Math.floor(Math.random() * ($(window).width() - orangeFish.width()));
- var tempSpeedTop = (Math.random() < 0.5 ? -1 : 1) * 1 + Math.floor(Math.random() * ($(window).height() - orangeFish.height()));
- $.when(
- $(IdRef)
- .animate({left: tempSpeedLeft, top: tempSpeedTop}, randNum(3500, 7500)).promise()
- ).done(function(){
- fishRandomMovement(IdRef);
- });
- }
- function randNum(min, max){
- return Math.floor(Math.random() * (max - min + 1) + min);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement