Advertisement
thetenfold

Untitled

Jul 24th, 2013
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // define these as global variables
  2. // or else you will get an error in ECMAScript 5/Strict mode
  3. var divWidth = 0,
  4.     divHeight = 0,
  5.     timer,
  6.     queue = [];
  7.  
  8. function growDiv() {
  9.  
  10.     // empty the queue
  11.     queue.length = 0;
  12.  
  13.     // queue up some elements to animate
  14.     queue.push(div1, div2);
  15.  
  16.     // animate the next element, if any
  17.     runQueue();
  18.  
  19. }
  20.  
  21. function runQueue() {
  22.     if (queue.length > 0) {
  23.         timer = setInterval(function () {
  24.             animate( queue.shift() );
  25.         }, 20);
  26.     }
  27. }
  28.  
  29. function animate(div) {
  30.     divWidth += 5;
  31.     divHeight += 5;
  32.     S(div).width = divWidth;
  33.     S(div).height = divHeight;
  34.     if (divWidth >= 100) {
  35.         clearInterval(timer);
  36.         divWidth = 0;
  37.         divHeight = 0;
  38.         runQueue();
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement