author | Dan |
Sat, 18 Apr 2009 23:03:36 -0400 | |
changeset 938 | 5d9060b4253f |
parent 582 | a38876c0793c |
child 1227 | bdac73ed481e |
permissions | -rw-r--r-- |
1 | 1 |
// @name The Fade Anything Technique |
2 |
// @namespace http://www.axentric.com/aside/fat/ |
|
3 |
// @version 1.0-RC1 |
|
4 |
// @author Adam Michela |
|
5 |
||
6 |
var Fat = { |
|
7 |
make_hex : function (r,g,b) |
|
8 |
{ |
|
9 |
r = r.toString(16); if (r.length == 1) r = '0' + r; |
|
10 |
g = g.toString(16); if (g.length == 1) g = '0' + g; |
|
11 |
b = b.toString(16); if (b.length == 1) b = '0' + b; |
|
12 |
return "#" + r + g + b; |
|
13 |
}, |
|
14 |
fade_all : function () |
|
15 |
{ |
|
520
4c16e87cfeae
Optmized a number of Javascript routines for better speed on pathetic Javascript interpreters.
Dan
parents:
1
diff
changeset
|
16 |
var a = document.getElementsByTagName("div"); |
1 | 17 |
for (var i = 0; i < a.length; i++) |
18 |
{ |
|
19 |
var o = a[i]; |
|
20 |
var r = /fade-?(\w{3,6})?/.exec(o.className); |
|
21 |
if (r) |
|
22 |
{ |
|
23 |
if (!r[1]) r[1] = ""; |
|
24 |
if (!o.id) o.id = 'autofat_'+Math.floor(Math.random() * 100000); |
|
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 |
if(!o) return; |
|
70 |
o.style.backgroundColor = c; |
|
71 |
}, |
|
72 |
get_bgcolor : function (id) |
|
73 |
{ |
|
74 |
var o = document.getElementById(id); |
|
75 |
while(o) |
|
76 |
{ |
|
77 |
var c; |
|
78 |
if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color"); |
|
79 |
if (o.currentStyle) c = o.currentStyle.backgroundColor; |
|
80 |
if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; } |
|
81 |
o = o.parentNode; |
|
82 |
} |
|
83 |
if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF"; |
|
84 |
var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/); |
|
85 |
if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3])); |
|
86 |
return c; |
|
87 |
} |
|
88 |
} |
|
89 |
||
582
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
520
diff
changeset
|
90 |
addOnloadHook(Fat.fade_all); |
a38876c0793c
Majorly reworked Javascript runtime stuff to use on-demand loading.
Dan
parents:
520
diff
changeset
|
91 |