pastebin

Paste Search Dynamic
Recent pastes
fade
  1. /**
  2.  * Author: Lachlan Hunt
  3.  * Version: 1.0
  4.  *
  5.  * Licence: Public Domain
  6.  * Attribution is considered ethical, but not required.
  7.  */
  8.  
  9. function fadeStep(element, pallet, step, delay) {
  10.         return function() {
  11.                 if (step < pallet.length) {
  12.                         element.style.backgroundColor = pallet[step++].hex();
  13.                         setTimeout(fadeStep(element, pallet, step, delay),delay);
  14.                 }
  15.         }
  16. }
  17.  
  18. function fade() {
  19.         var colEnd = new Color(document.getElementById("color").value);
  20.         var steps = parseInt(document.getElementById("steps").value);
  21.         var delay = parseInt(document.getElementById("delay").value);
  22.  
  23.         var element = document.getElementsByTagName("body").item(0);
  24.         var colStart = (element.style.backgroundColor) ? new Color(element.style.backgroundColor) : new Color("white");
  25.  
  26.         var pallet = colStart.blend(colEnd, steps);
  27.        
  28.         setTimeout(fadeStep(element, pallet, 0, delay), delay);
  29. }
Parsed in 0.004 seconds