b2evolution PHP Cross Reference Blogging Systems

Source: /rsc/js/fadeout.js - 89 lines - 2754 bytes - Text - Print

   1  // @name      The Fade Anything Technique
   2  // @namespace http://www.axentric.com/aside/fat/
   3  // @version   1.0-RC1
   4  // @author    Adam Michela
   5  // Released under Creative Commons Attribution-ShareAlike 2.0 license
   6  
   7  var Fat = {
   8      make_hex : function (r,g,b)
   9      {
  10          r = r.toString(16); if (r.length == 1) r = '0' + r;
  11          g = g.toString(16); if (g.length == 1) g = '0' + g;
  12          b = b.toString(16); if (b.length == 1) b = '0' + b;
  13          return "#" + r + g + b;
  14      },
  15      fade_all : function ()
  16      {
  17          var a = document.getElementsByTagName("*");
  18          for (var i = 0; i < a.length; i++)
  19          {
  20              var o = a[i];
  21              var r = /fadeout-?(\w{3,6})?/.exec(o.className);
  22              if (r)
  23              {
  24                  if (!r[1]) r[1] = "";
  25                  if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
  26              }
  27          }
  28      },
  29      fade_element : function (id, fps, duration, from, to)
  30      {
  31          if (!fps) fps = 30;
  32          if (!duration) duration = 3000;
  33          if (!from || from=="#") from = "#FFFF33";
  34          if (!to) to = this.get_bgcolor(id);
  35  
  36          var frames = Math.round(fps * (duration / 1000));
  37          var interval = duration / frames;
  38          var delay = interval;
  39          var frame = 0;
  40  
  41          if (from.length < 7) from += from.substr(1,3);
  42          if (to.length < 7) to += to.substr(1,3);
  43  
  44          var rf = parseInt(from.substr(1,2),16);
  45          var gf = parseInt(from.substr(3,2),16);
  46          var bf = parseInt(from.substr(5,2),16);
  47          var rt = parseInt(to.substr(1,2),16);
  48          var gt = parseInt(to.substr(3,2),16);
  49          var bt = parseInt(to.substr(5,2),16);
  50  
  51          var r,g,b,h;
  52          while (frame < frames)
  53          {
  54              r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
  55              g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
  56              b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
  57              h = this.make_hex(r,g,b);
  58  
  59              setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);
  60  
  61              frame++;
  62              delay = interval * frame;
  63          }
  64          setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
  65      },
  66      set_bgcolor : function (id, c)
  67      {
  68          var o = document.getElementById(id);
  69          o.style.backgroundColor = c;
  70      },
  71      get_bgcolor : function (id)
  72      {
  73          var o = document.getElementById(id);
  74          while(o)
  75          {
  76              var c;
  77              if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
  78              if (o.currentStyle) c = o.currentStyle.backgroundColor;
  79              if ((c != "" && c != "transparent"
  80                      && ( navigator.userAgent.toLowerCase().indexOf("konqueror") == -1 || c != "#000000" ) // Workaround for Konqueror, see http://bugs.kde.org/show_bug.cgi?id=130225
  81                  ) || o.tagName == "BODY") { break; }
  82              o = o.parentNode;
  83          }
  84          if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
  85          var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
  86          if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
  87          return c;
  88      }
  89  }

title

Description

title

Description

title

Description

title

title

Body