Advertisement
TheScriptan

Untitled

Nov 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. var orangeFish = $("#fish1Id");
  2. var blueFish = $("#fish2Id");
  3.  
  4. fishRandomMovement(orangeFish);
  5. fishRandomMovement(blueFish);
  6.  
  7. function fishRandomMovement(IdRef){
  8. var tempSpeedLeft = (Math.random() < 0.5 ? -1 : 1) * 1 + Math.floor(Math.random() * ($(window).width() - orangeFish.width()));
  9. var tempSpeedTop = (Math.random() < 0.5 ? -1 : 1) * 1 + Math.floor(Math.random() * ($(window).height() - orangeFish.height()));
  10.  
  11. $.when(
  12. $(IdRef)
  13. .animate({left: tempSpeedLeft, top: tempSpeedTop}, randNum(3500, 7500)).promise()
  14. ).done(function(){
  15. fishRandomMovement(IdRef);
  16. });
  17. }
  18.  
  19. function randNum(min, max){
  20. return Math.floor(Math.random() * (max - min + 1) + min);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement