This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Untitled

By: thetenfold on Jul 24th, 2013  |  syntax: JavaScript  |  size: 0.79 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data