Board logo

标题: 网页之不断弹射的文字-特效 [打印本页]

作者: zw2004    时间: 2008-1-21 20:55     标题: 网页之不断弹射的文字-特效

<style type="text/css">/ F) W  a2 l' N8 T
#supertext {3 n7 C, y9 b7 ]4 \0 K3 N, m+ I
position:absolute;/ ^4 j/ n3 n% O
left:0;
( F  X6 G1 U6 r  Etop:0;6 B' U4 P% ^, {# Q, C
visibility:hide;
, S8 G2 b6 h, C# T0 X- H! Xvisibility:hidden;
; ]; T- O1 f1 J, ~, ~3 u, Q}
5 {  v' r3 ^" e</style>
- s5 I! Y5 v7 ]' {7 r<script language="JavaScript1.2">% N. Q3 r9 _8 F' i1 d! X
<!-- 改变下的字体的大小。颜色-->6 p5 G' A# T$ Y$ [
var thecontent='<h2><font size="2" face="宋体" color="FF0000">欢迎光临七色风网页家园</font></h2>'
  b5 ]& c( l6 ivar hidetimer='';
& `9 n0 N1 y$ b1 y<!-- 改变下的弹跳速度-->9 Z; f; k; N# ~7 S
var BallSpeed = 20;; D5 `, t2 ^4 Q0 q/ M7 s8 _
var contentWidth;; N: d' r  H8 x# }+ P9 A+ K. q
var contentHeight;
4 D  {; C. T8 uvar maxBallSpeed = 50;; N6 _) B; _1 V

5 l) q4 P- q' A) L# D2 ]& ], N7 [2 a
var xMax;1 |9 M( Z* F' a- g8 x7 q# ?1 W
var yMax;
5 p0 }8 T8 n4 H# ^, ?1 Mvar xPos = 0;
3 P$ F- J/ A0 D( O, ^" yvar yPos = 0;
8 Z( F& O. v5 M$ E& u& w2 ivar xDir = 'right';
6 H7 r3 ?, l5 k$ ?1 Q& A0 n5 Avar yDir = 'down';3 t& [* E: g) U6 |
var superballRunning = true;
$ o: m3 k! P4 w* R( xvar tempBallSpeed;
# O4 `9 `- ^! O! R2 Dvar currentBallSrc;
8 M9 ?( l# ~8 a- ^: L, y; R4 ^var newXDir;% O( r1 v% _/ D: S9 Z% v
var newYDir;
, a3 q; W: F% z5 a  N+ \9 g5 m9 l$ j
: G2 @9 f& F/ B0 gfunction initializeBall() {9 @1 L% ?  i: D/ ]- D/ _, f1 ~
   if (document.all) {
8 @( @0 ~( c/ L8 s- w$ N9 `1 k      xMax = document.body.clientWidth, R0 c6 l1 A+ Q2 Q
      yMax = document.body.clientHeight
% x. \4 F8 l! b& b* l% R2 E      document.all("supertext").style.visibility = "visible";
0 r+ G2 d. P3 d$ Y8 R      contentWidth=supertext.offsetWidth
2 E. {0 P  f% c9 e6 i2 Y& O$ r3 t      contentHeight=supertext.offsetHeight
$ e: k& M% `9 N2 }/ P3 `  V      }- n1 [1 B1 f/ `) S5 P- j" m
   else if (document.layers) {
( u, l1 A/ }  p2 d      xMax = window.innerWidth;: z1 T' g& Y, W$ w. b7 m8 O
      yMax = window.innerHeight;3 x# e$ Z* F, x6 z+ y
      contentWidth=document.supertext.document.width8 Z5 O: W; I/ n# X# O
      contentHeight=document.supertext.document.height( [6 ~9 t& ]6 J
      document.layers["supertext"].visibility = "show";! E0 |! ^. g9 Y! L$ ]/ h
      }1 H# Y; S0 y2 N4 O$ o
   setTimeout('moveBall()',400);
% e0 `8 C3 v+ W9 C2 q4 ^! B   if (hidetimer!='')
2 [. p  J/ E/ Y- s* w2 }" Z/ |   setTimeout("hidetext()",hidetimer)
8 q7 X, ]' Q/ a4 F* U$ e   }- V4 q. a1 J, b+ ]1 c5 G
! ]7 F' P: a& V0 b% v8 K4 H
function moveBall() {0 ]5 ^' d3 A2 J/ q, [2 s, ?
   if (superballRunning == true) {
) S4 }5 y; M: Y% ?7 v# s) A: ~" _      calculatePosition();
$ z, u' n  W9 U      if (document.all) {3 `8 y# F& @1 G# c: ?8 N
         document.all("supertext").style.left = xPos + document.body.scrollLeft;5 X# }5 x  n& _" u2 ^
         document.all("supertext").style.top = yPos + document.body.scrollTop;9 _: l/ q" F2 d4 Q& k; M) d) }4 y3 p
         }
2 A* S0 Q  ~1 M% `      else if (document.layers) {+ g, S* C9 G6 T2 d
         document.layers["supertext"].left = xPos + pageXOffset;; s1 |6 \4 q* c! L
         document.layers["supertext"].top = yPos + pageYOffset;. V! a; I. y& @9 b. A' v5 P
         }& g8 d4 h9 [9 T4 W: }
      animatetext=setTimeout('moveBall()',20);* y6 C/ V8 @9 V
      }
* a' K. e8 ?6 [; g" [; q$ N   }% W9 \+ z+ T$ L7 a

$ ]+ O5 |5 i! Q( X, Kfunction calculatePosition() {5 w$ D! L& \/ j
   if (xDir == "right") {8 n! I  M0 v: i
      if (xPos > (xMax - contentWidth - BallSpeed)) {9 t/ ~% c& S2 s, K5 T% I( C* N
         xDir = "left";/ l8 W! G) w. G# ]
         }
' y$ u( ?. W# n" j" n      }$ |! ?# ]" {7 l1 h+ Q+ f& s
   else if (xDir == "left") {
2 }- l7 K' E! l1 |      if (xPos < (0 + BallSpeed)) {
- }: {, q  c; U7 [+ j         xDir = "right";( e, l* x" d0 [! c2 Z& A. P/ ?+ Y% h+ }
         }. D! F" z& p3 ^
      }$ `1 V, T+ q( K
   if (yDir == "down") {
8 F+ t* @" K. D5 P! l  w      if (yPos > (yMax - contentHeight - BallSpeed)) {5 T4 ]+ L- r9 [  O" v3 n3 M' g
         yDir = "up";
8 ^( j4 R, Z: F# X         }* z4 |# p5 [4 B2 Y6 \* u1 d
      }
/ v7 u* f  N, D   else if (yDir == "up") {2 i( o5 }6 \/ p) F& R. A6 {9 F
      if (yPos < (0 + BallSpeed)) {9 e# J% k' N% v1 D% G
         yDir = "down";
! r5 N# s) a. I% f, u         }
0 U4 F' _# h2 B7 ^      }
7 E' C6 m- p1 i   if (xDir == "right") {
- E$ R  @# P2 y  D: v      xPos = xPos + BallSpeed;, Z( c3 j4 ^( V% K+ E, z7 C4 ?
      }3 `0 Y" @' v: F# R3 R8 X, B, k
   else if (xDir == "left") {
  F2 z: M- |+ W( K      xPos = xPos - BallSpeed;
! @) g+ u0 A/ c4 ^2 {" a      }
, k3 k" ^: W& y   else {
7 V* Y( D$ @2 V; Q) n9 T- n/ v. ^      xPos = xPos;
7 o- A% s% ^* g4 T8 W; m      }
8 Y4 i2 `" ~- I' o: x! d4 I) n   if (yDir == "down") {8 a+ _% l0 U$ I  q
      yPos = yPos + BallSpeed;
# {4 L0 V; i- n# Q9 l, J* }4 r, O      }
! Z. m5 ?* x0 k  @( E& [# A   else if (yDir == "up") {
: J5 `2 M4 a1 K8 |( H! B% f+ y      yPos = yPos - BallSpeed;, y- B3 A3 }" m- W. }# \
      }  R( n* P8 a3 [3 q( u' T
   else {* i1 D* Z1 k% C) e7 P
      yPos = yPos;3 h5 l0 z/ S0 ?* e2 {
      }
$ h0 D6 H6 T) x4 w: c: {3 F   }
2 W. {6 h3 V) t- e; ^3 L, z, O' h  _3 x5 H1 W0 I5 v5 r
function hidetext(){
9 G& `- a8 V& T$ @if (document.all)+ |3 F, Q6 _3 N- q
supertext.style.visibility="hidden"
3 f7 A( T8 J3 Z; aelse if (document.layers)
% S6 |; |+ T1 Q$ r& d4 y7 {document.supertext.visibility="hide"
' B2 s+ n: }# Q6 cclearTimeout(animatetext)! X1 A  h! r9 s/ X5 L; C# W
}/ s7 P+ X+ J: T9 F( P6 X4 C
! f2 ?  s; Y& r/ q
if (document.all||document.layers){6 n3 z7 J, k0 l0 D) |
document.write('<span id="supertext"><nobr>'+thecontent+'</nobr></span>')
: }0 {0 H+ a+ j9 lwindow.onload = initializeBall;* V( h4 A. R3 W7 c4 ?. N% j
window.onresize = new Function("window.location.reload()");
" p; J6 L; }: T* V}
" h9 ^: t' @, M. B
) y2 u: k9 E2 B</script>




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