SHARE
TWEET

Untitled

a guest Jan 17th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function animateDiv() {
  2.     for (z = 0; z < 50; z++) {
  3.         var newq = makeNewPosition();
  4.         var oldq = $("#" + z).position()
  5.         var speed = calcSpeed([oldq.left], newq);
  6.  
  7.         if (document.getElementById(z).class != "b") {
  8.             $("#" + z).animate({
  9.                 left: newq
  10.             }, speed, function() {});
  11.         }
  12.     }
  13.  
  14.     setTimeout(function() {
  15.         animateDiv();
  16.     }, 0.1);
  17. }
  18.  
  19. function makeNewPosition() {
  20.     var w = $('#content').width() - 25;
  21.     var nw = Math.floor(Math.random() * w);    
  22.     return [nw];
  23. }
  24.  
  25. function calcSpeed(prev, next) {
  26.     var y = Math.abs(prev - next);
  27.     var greatest = y;
  28.     var speedModifier = 0.1;
  29.     var speed = Math.ceil(greatest / speedModifier);
  30.     return speed;
  31. }
  32.    
  33. function animateDiv() {
  34.  
  35.     function animateItem(item) {
  36.         if (!item.hasClass("b")) {
  37.             var newq = makeNewPosition();
  38.             var oldq = item.position()
  39.             var speed = calcSpeed([oldq.left], newq);
  40.             // make sure animations can never accumulate and
  41.             // then start the next one
  42.             item.stop(true).animate({
  43.                 left: newq
  44.             }, speed, function() {
  45.                 // run next animation on this object when this one finishes
  46.                 animateItem(item);
  47.             });
  48.         }
  49.  
  50.     }
  51.     // start all animations
  52.     for (z = 0; z < 50; z++) {
  53.         animateItem($("#" + z));
  54.     }
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top