Board logo

标题: 网页之文字的循环闪动特效 [打印本页]

作者: zw2004    时间: 2008-1-21 20:48     标题: 网页之文字的循环闪动特效

<script language="javascript" type="text/javascript">% e( E9 l& {* R: e$ Q" J, A4 g4 _
<!--9 s8 k1 ~5 m! V, g
// convert a single digit (0 - 16) into hex( D- d2 l, d& X2 n- L4 j
function enHex(aDigit)
0 Q6 E  q2 V. `{7 s# F/ W; R+ ]& c
    return("0123456789ABCDEF".substring(aDigit, aDigit+1))
% R9 @% Z1 O4 U  I% M}" A6 D1 w" ]4 ?1 j2 [
// convert a hex digit into decimal
1 W+ j" U3 m; w: \8 g  |) `  ffunction deHex(aDigit)0 Y% S- y1 W9 H3 Q* r: p
{) [. z4 X3 y4 m5 K8 g" G, ^
    return("0123456789ABCDEF".indexOf(aDigit)). z+ Z) n2 {9 \! L
}
# R& ^# D4 T" r0 R* R- i
3 h/ F  R( c6 N" _4 ]8 b5 y( Z7 N// Convert a 24bit number to hex( C; E7 i! F4 h4 J& ?  t* i/ F) |
function toHex(n). F' g* c$ m  E8 p4 D
{
6 f! o5 |$ N7 H8 p- h+ z    return (enHex((0xf00000 & n) >> 20) +
  q- R- N; n) b# w# n* T3 `            enHex((0x0f0000 & n) >> 16) +
! g7 R4 o3 }: t- R# h6 b3 A            enHex((0x00f000 & n) >> 12) +  }) p) P" Q3 Y; E
            enHex((0x000f00 & n) >>  8) +
4 |% s; J/ d& N* r# e: g0 @9 D            enHex((0x0000f0 & n) >>  4) +
1 o1 e8 I$ S; v' s& A0 G# P            enHex((0x00000f & n) >>  0))! N& ]+ x2 o1 S8 d4 ]9 c3 |
}
7 Y. G( Z$ F" @4 v1 F- G, E$ F8 e// Convert a six character hex to decimal5 A+ F* u5 {+ R9 f' C3 p
function toDecimal(hexNum). G6 e/ `' X+ N0 _) }4 j: \* R
{( r$ X- y3 H; d7 d! k$ ]
           var tmp = ""+hexNum.toUpperCase()
, L7 h1 V1 y) L, F    while (tmp.length < 6) tmp = "0"+tmp
- s5 a( u0 u- L  J  a           return ((deHex(tmp.substring(0,1)) << 20) +. x, g1 O3 E6 U
                   (deHex(tmp.substring(1,2)) << 16) +
$ O  @$ Q) S# |: R0 ]            (deHex(tmp.substring(2,3)) << 12) +. X% t. G# V4 e
            (deHex(tmp.substring(3,4)) << 8) +6 x) j; v0 W& _/ }. [0 _. \
            (deHex(tmp.substring(4,5)) << 4) +$ i$ ]' z. w/ E% U
                   (deHex(tmp.substring(5,6))))
+ p; b/ e# P2 \+ [}
7 l/ J4 Z! M7 R+ d///////////////////Shimmering Links/////////////////////# A* r+ l& y9 s/ m, z
//global variables" L% u1 h& R, Y% V( C/ p
var hoverColour2 P- |3 A4 }4 L$ y+ z# p2 z
var numLinks;
! W+ \: X! m8 b8 B: ivar rate;
; D- K. A7 f  V& E4 Qvar numFadeLevels;& b; y% Q  ~, g6 a  v7 W, D
var bgR;
# n- }' \+ c7 e( p7 W# m; E- S+ ~var bgG;" ^' h6 T( e: t/ L
var bgB;* x/ H  F4 p7 u* Q. g7 k
var currR;
/ U% a) Q/ @9 ]% |; S% D1 n( f5 e" }var currG;
6 m$ X- y* H- K) fvar currB;
% P' A# B6 o0 lvar count;  Z% z. [. t- L7 S: N1 _' ^, C
var fadeOut;$ @0 i% U( F0 B8 L  h$ h* {
var continuous;
9 K& p  I* {" A3 {0 A2 \var newColour;) q* n1 }& T5 \' G+ Y
var tID;
" y4 ?2 c. G& C! nvar redInterval;
9 J$ \0 Z( _+ ?4 K  n+ x3 p6 Dvar greenInterval;! O. g' _# T+ p- o. t* ?, [, ~5 l
var blueInterval;
9 W8 n! ]$ [  m0 _function initLinks(mouseOverColour, numberOfLinks, fadeOutColour)% {6 ~: Z  k0 q
{. b/ X; k) A/ l) r* J1 t; Y& Z
        hoverColour = mouseOverColour;7 y: J8 s) G- E# R
        numLinks = numberOfLinks;
, g0 T5 n( h) M0 w        rate = 1;
2 z( O( {3 ~1 p! w/ u        numFadeLevels = 30;
; Q, D* |& [. G! B. m/ D% Q' y( q        function initArray(theArray, length, val)" ?+ i+ a2 z6 C( P. W5 I% y7 V
        {
8 G. w% n# U" l5 F                for(i=0;i<length;i++)4 Z: e& e: u# t; j% s% z; ^
                {, X+ {: T  x" k1 D7 h+ i. Y
                        theArray = val;
7 Y7 f+ f* D9 E& k1 H5 M, X, g                }
8 U5 m; B+ z) ]& `9 T        }
5 U% i/ x. s: i1 ]1 Q+ p; s        bgR = '0000' + fadeOutColour.substring(1,3)
# y$ I- I( f; B! W+ W        bgG = '0000' + fadeOutColour.substring(3,5); }* D% p; C* N0 Q4 v; `  u
        bgB = '0000' + fadeOutColour.substring(5,7)
' H; B; @( s! ~        currR = new Array(numLinks);% I$ K0 U+ p) X5 l2 ^6 F) T
        currG = new Array(numLinks);) W" S  [7 C0 t- p7 L
        currB = new Array(numLinks);
+ n# E2 v3 [9 z. I9 [. x: X) ~, R        count = new Array(numLinks);
4 p, U/ g/ x; @; S! y0 N, H        fadeOut = new Array(numLinks);8 ?8 r+ G0 B6 y% e
        continuous = new Array(numLinks);6 k4 K8 I+ W$ n8 z$ S* c
        newColour = new Array(numLinks);
, u# I. h. e0 g# Z        tID = new Array(numLinks);  v; j+ u6 @. |, C+ Q- L
        redInterval = toDecimal(bgR) / numFadeLevels;7 i+ \* z: C  }* U
        greenInterval = toDecimal(bgG) / numFadeLevels;4 r1 n2 W' n# D# i1 V
        blueInterval = toDecimal(bgB) / numFadeLevels;+ O& r- m7 k% G: q+ b; l6 d
        initArray(currR,numLinks,0);
: k4 S3 [7 q8 A  K. F7 F* U        initArray(currG,numLinks,0);
% N6 \' C9 u) y" |! d$ x2 X2 G6 o6 P        initArray(currB,numLinks,0);
; F3 [. ~6 D% G5 t        initArray(count,numLinks,0);
3 ?6 o! O( E/ C" g; e7 f7 b) G        initArray(fadeOut,numLinks,true);" a' y& d: z! Z8 O+ K4 y$ f
        initArray(continuous,numLinks,true);0 W* |% ~* ]8 K% k6 i/ S; D
}        ) v9 L* v/ B$ c7 Z. Y5 K! H( [& t' Y5 d3 u
function startFade(id)! X$ B1 ^6 j$ d, S% v8 K2 M
{
5 o2 w8 [' F- {4 F        if(fadeOut[id] == true)
. w1 Q* m1 z& I! m        { /*move colour towards background colour (increment)*/9 r, {5 @" _2 a9 i; E
                currR[id] += redInterval;
( ~% `. C, Q- N" H$ R9 d                currG[id] += greenInterval;
" z. c  ?$ E/ q& ?, \) i( w                currB[id] += blueInterval;
7 ^  _6 f  h( C9 H1 w4 A7 p                newColour[id] = '#' + (toHex(currR[id])).substring(4,6) + (toHex(currG[id])).substring(4,6) + (toHex(currB[id])).substring(4,6);
8 m+ _! a" s) T# K. u8 d3 o5 L                if(++count[id] == numFadeLevels)+ l/ e! l: p. B  y/ F+ G
                {& q# j0 O6 `2 y7 x" ^
                        fadeOut[id] = false;
) r9 A. d- i2 d, L: A                }# G4 y5 D# z; I% d& h
        }
" h) J0 f( D' Y: k3 m4 ?) g        else
6 T1 L! F; D* ]& a- m6 I        {1 Q, _# _4 p7 Q0 T1 {
                currR[id] -= redInterval;7 W8 c" z) i" o2 v4 [' R. ^

6 H0 E" v( a. |$ N3 \- d* _0 E, a                currG[id] -= greenInterval;3 J# ^9 w1 U! ?! u* c. C) l! ]

# S+ n  q1 P" @3 p' n5 ]% N1 y                currB[id] -= blueInterval;
0 |& m- A! n5 k' D- `
- r) q' E% n+ `& I' h8 E                newColour[id] = '#' + (toHex(currR[id])).substring(4,6) + (toHex(currG[id])).substring(4,6) + (toHex(currB[id])).substring(4,6);8 f6 e4 X& N5 E3 w* R( s0 ~
3 p8 u9 M7 h' u* P3 R
                if(--count[id] == 0)5 d+ S4 x- P+ g4 R6 `) q5 T

! R# B2 \4 i0 c                {
1 r" n9 |$ d3 u7 f! @& P% s% x3 i8 W  V
                        fadeOut[id] = true;
' z9 _4 s- t$ ~" ~% O$ h  v# G; [- u9 p
                }% U: t' Z6 t+ R# D) K
+ M8 q- Y' I! I" b, L# \+ \
        }+ X3 O% ]& H- L

' b: Y! P' ^* a5 B6 X1 i        if(continuous[id] == true)
6 g$ V! X+ Y6 H. C( d3 h! W; c3 W6 Y) ^; E" G8 s/ b& }
        {
5 K8 r: O+ e, f! I, j" [2 a( c1 D2 F5 _# M1 `# d3 U
                document.getElementById(id).style.color = newColour[id];               
( e% {! y" I, ~7 r& c( K
! p5 |* L% \0 w3 K/ H% I        }: c: ~: \& M: p4 E0 S
7 |: m/ b9 V* e% L7 g) ]1 j, d
        else' W9 z9 Z8 @' q
' `7 p* x" e0 Q" v6 y
        {
$ u1 [, b, V4 b. \& O, \
) b9 B2 F. j' {1 J                document.getElementById(id).style.color = hoverColour;
5 O. ?* s9 I( V6 @& F
% U4 @) L6 ?% v6 X3 j* M2 P        }. G  Z9 X) R7 }' \
! ~$ |7 @/ Q  t2 f3 l0 q6 c1 A
        clearTimeout(tID[id]);/ A$ H/ `; B% Q# K; R/ u- _

6 P1 W( [0 Z) v* H        tID[id]=setTimeout('startFade(' + id + ')', rate);
1 K, w2 F& b, r4 F; |/ Z2 j) d* m9 S; a0 J# N) I
}, _' s' {$ W# a- D8 e% ^: `
: f: ]2 c9 E# _2 W# Y
function continueFade(id)
  j- x3 {/ w. y( z/ U( U% J
8 u( d9 n, {  m: W; o{
1 g: P) B, T$ P0 O" I5 M/ i2 R- O/ g3 E& q( k5 j
        continuous[id] = true;
2 b6 q/ \7 ^. U* B8 _! z- P/ g. v) ]& [8 O3 A0 d8 E
}) e4 R8 Z! R" @5 u% K8 M' H! P
- [1 v9 H. m+ l& j9 p) m8 W0 w* n
function stopFade(id)4 b8 z( `4 k7 _& v
' _: u- i- R4 _! [% y+ \2 A
{
" }9 \* H& ?: B" k4 \* n
* e: G: z; d  o/ k        continuous[id] = false;& ]: R" L& `: J1 }+ y

& K6 g* ^5 T4 d}
3 K& k6 V6 A# H2 T/ Z1 f- A3 M
. t) Q% W0 H& Z0 g- V9 h/ z& Lfunction StartTimers()" d) L  F3 |2 G( K- D3 k- q6 x

; k0 w" a. X0 d! Z7 Q: I+ R{        //set up an initial set of timers to start the shimmering effect/ H) T, E5 J- a% t9 u" ^

& j1 ~! t+ e9 Y) a        for(id=0; id<numLinks; id++)
9 u! }) N# p' b( c! W* W; g
/ t, ~: l' h% v( f7 }6 F        {
8 T- Y- |% ?/ D5 B9 f+ x7 S' `! I8 ~3 Y3 @5 h. i
                t=setTimeout('startFade(' + id + ')', id*100);
& j4 u& r* _* C" |: g9 x1 b4 ?* b; q/ k  \8 D$ c3 L
        }: |6 F  P5 E6 \
  j5 E* b" H; f. {* M% @1 I
}. @, d+ M, |) w# T- A* T

0 s9 G# A6 _- s' P  O/ G% z# ~//format = initLinks('mouse-over colour', 'number of links', 'fade-out colour')' V3 r& ]1 ^: _6 H5 P
( |1 `, D8 K8 y3 @+ a* n
initLinks('#FF0000', 6, '#FFCC77');7 H7 k1 T% o8 N+ h- V
- t# ~" F8 T+ r
//-->2 l0 X1 ?4 J# \, k

: R( g/ C9 ~& D- @</script>: E- D0 ~& }! e, c2 s5 v/ x0 B
<a class="links" id="0" onmouseover="stopFade('0');" onmouseout="continueFade('0');" href="http://7wind.com/">国际域名:58元
9 R- q7 X, X3 W  o7 U</a>
2 o- {0 \! `6 K" `8 s" P- N6 f4 h<br>
5 H) P5 S8 B# E4 Z. u- f<a class="links" id="1" onmouseover="stopFade('1');" onmouseout="continueFade('1');" href="http://7wind.net/">国内域名:110元</a>; T1 {! x% V4 a0 T% x9 ]8 }
<br>
! T0 P# f+ W; f/ a% T% v, y# [<a class="links" id="2" onmouseover="stopFade('2');" onmouseout="continueFade('2');" href="http://7wind.net">新一代企业信息系统</a>" h, W) a9 Z3 x6 [3 S# T: W# P& Y
<br>        - S, J& B/ t6 S+ T! V* K4 `: y
<a class="links" id="3" onmouseover="stopFade('3');" onmouseout="continueFade('3');" href="http://7wind.net">新一代网络商城</a>
4 p: C7 L; U" u# y<br>
9 E% A9 W3 \0 i7 W" ]% @<a class="links" id="4" onmouseover="stopFade('4');" onmouseout="continueFade('4');" href="http://7wind.com/">全新的自助建站方式</a>
& @; w! s; z% T9 o- x0 {& z<br>& L8 Y# R+ a$ U8 \6 v5 ?, R
<a class="links" id="5" onmouseover="stopFade('5');" onmouseout="continueFade('5');" href="http://www.webdevelopersjournal.com/">全新的设计理念</a>, S" z6 b( E* T: C) V* O0 C
<script language="javascript" type="text/javascript"># L) f/ H* H3 t3 j
<!--: s. ?8 S9 C9 L6 V8 l
setTimeout('StartTimers()', 1000); //initial 1 second delay to allow page to load and ensure smooth shimmering
2 w& o! E, W% e7 r2 m4 l' u//-->
" Y( l1 Q! |0 l8 [+ a</script>




欢迎光临 捌玖网络工作室 (http://www.89w.org/) Powered by Discuz! 7.2