标题:
网页之不断弹射的文字-特效
[打印本页]
作者:
zw2004
时间:
2008-1-21 20:55
标题:
网页之不断弹射的文字-特效
<style type="text/css">
. `4 v9 j; s8 {7 z
#supertext {
# k E* A$ W. w/ e; E
position:absolute;
* y* y" e! i+ t
left:0;
: y" A9 A4 f( Q. p( f3 F. P
top:0;
5 X1 J5 _- m. w2 w4 W5 {
visibility:hide;
2 n! Y9 W! p' C" U
visibility:hidden;
5 M. H- Z; g8 X
}
+ U" i {* a/ ~
</style>
" y: C$ F. A( A# R* Y
<script language="JavaScript1.2">
, j! P& |. f+ n4 f1 S
<!-- 改变下的字体的大小。颜色-->
- o2 `, p+ R0 R1 H* a% {6 q
var thecontent='<h2><font size="2" face="宋体" color="FF0000">欢迎光临七色风网页家园</font></h2>'
) x2 @" D. U! _2 M
var hidetimer='';
) ^7 I, G4 l2 z) J* R
<!-- 改变下的弹跳速度-->
+ {/ k4 m; o; v5 e* P* X
var BallSpeed = 20;
0 Q1 B& D. E1 ]2 G9 K @
var contentWidth;
h: y' `9 N5 J* b4 f* [
var contentHeight;
' R! ~# d% q7 n9 ~4 T' e
var maxBallSpeed = 50;
( C5 e8 O* }0 a, w- E* e$ E1 n
" e' c& q3 U% k# F* @% N
: X# O# d2 _! Q! l6 K
var xMax;
! r7 |. t' h) q4 v! i
var yMax;
! W: \' A) f9 y# {; r
var xPos = 0;
0 P& ~3 m% M# A4 @' ^! G z2 e
var yPos = 0;
: l& y! y) P2 K% y/ b* S/ s& }0 ]- P
var xDir = 'right';
+ G6 S$ e) n+ b5 w; s
var yDir = 'down';
8 T3 E% t$ L. I% h( n& v( h# n
var superballRunning = true;
) \, z! y7 T1 k$ a$ v! |' Y6 l v( Q
var tempBallSpeed;
: {4 Y* C* e d/ l7 q
var currentBallSrc;
( G4 B2 O: ^6 g6 \
var newXDir;
3 g$ F. q* [- d9 M; ]: g2 f
var newYDir;
+ f+ q; l* E% [3 }8 W
& V- g) P$ V! E; l
function initializeBall() {
/ g+ k1 U3 _* y7 o I
if (document.all) {
# s; g6 L; D# T9 D$ Z0 D* Y
xMax = document.body.clientWidth
8 }) w% b. l6 i( S
yMax = document.body.clientHeight
! Q6 }( y, D* R$ a4 P( q4 F7 K
document.all("supertext").style.visibility = "visible";
1 u8 a# l" v) Z
contentWidth=supertext.offsetWidth
2 Z2 e- U% f: x* z# k) \- L0 ^8 ^7 h
contentHeight=supertext.offsetHeight
9 ]' O. p" t3 C
}
# M0 m: z7 z5 d+ _ U: n
else if (document.layers) {
' S% W( v+ {" x0 q# ]2 z
xMax = window.innerWidth;
h9 ?3 F( o( `4 D1 `; S& d
yMax = window.innerHeight;
% B E, i5 l1 @
contentWidth=document.supertext.document.width
: U& U% U4 P' o
contentHeight=document.supertext.document.height
7 P* E( b; A H" |
document.layers["supertext"].visibility = "show";
) g7 m! h/ c6 P- x; W6 _
}
: E! s! V5 j u) e8 t
setTimeout('moveBall()',400);
1 B3 N _: s& N, B! F
if (hidetimer!='')
! q9 G% e' H! K- |0 g
setTimeout("hidetext()",hidetimer)
9 ^7 s4 [- P8 S/ `9 d% @' W
}
- R) q+ V, n/ g T3 a
) e1 A/ ~) a1 ?+ c; G
function moveBall() {
2 m' D# G9 H; y: d$ e
if (superballRunning == true) {
+ R, S2 q4 P: {. A' j
calculatePosition();
. |' W3 U0 u) A1 W! n, j$ A# C
if (document.all) {
2 Q/ @8 n( {7 ]# k$ Q8 r
document.all("supertext").style.left = xPos + document.body.scrollLeft;
$ o O* B1 T4 z
document.all("supertext").style.top = yPos + document.body.scrollTop;
X, Q: d7 G2 p. b. y
}
w+ K/ f0 U8 B1 c
else if (document.layers) {
# Y5 q/ b3 B# _2 D7 Q- E
document.layers["supertext"].left = xPos + pageXOffset;
/ i; r/ T& \ N* D
document.layers["supertext"].top = yPos + pageYOffset;
, r( z* H9 Y- T& l. b- N
}
8 P; n8 }0 y. c8 u4 ?( \ _% Z$ K
animatetext=setTimeout('moveBall()',20);
0 N7 ?; V. O$ `) r
}
+ W8 _* j3 ?9 E" E1 @# Z+ T
}
0 j( P: F9 H) A" b# ]" v! o- ]' U h
# J' J7 ~% @# W, q J8 C: L
function calculatePosition() {
3 x, u% i4 w1 P" X5 e6 l
if (xDir == "right") {
6 |9 X: g; i! i: f
if (xPos > (xMax - contentWidth - BallSpeed)) {
w2 a! O, V# v- v
xDir = "left";
Z5 R3 T j3 H* z; F* e" j, e' y
}
$ h5 q( M/ D$ \
}
8 D: Q) ~4 M( D6 ]! v6 K9 {+ g
else if (xDir == "left") {
* C+ S- D; G0 M5 D# y, i( l
if (xPos < (0 + BallSpeed)) {
& a. g' h+ ^* A1 [
xDir = "right";
" B9 k$ i! x. B' p, A
}
/ j) q( g) K: a d' {
}
; a7 e9 R; i6 D2 M. T& p7 R$ k" k$ ]
if (yDir == "down") {
" Z/ K" y/ j( O3 Q
if (yPos > (yMax - contentHeight - BallSpeed)) {
( h. F6 I( Z5 B7 \
yDir = "up";
3 x. ?: Q2 W+ \: S# J
}
1 f+ j, {* ~: R, O' K& m# [
}
5 G4 ~2 ]6 a# J. e
else if (yDir == "up") {
5 j0 j; x" A9 O7 Y7 a) I0 C
if (yPos < (0 + BallSpeed)) {
4 T6 \* m& q( _
yDir = "down";
8 r8 F* ?0 W0 t3 D' w
}
6 ?$ J! _! ?) X& g( N: G4 U
}
$ ]. W+ c) }& ^% }6 [8 ]6 M+ a4 K
if (xDir == "right") {
& o6 X7 \+ x5 I. B
xPos = xPos + BallSpeed;
- }( j# s N2 d" c# w' z
}
0 Y6 O# b' e/ {" C; H% O- i* o
else if (xDir == "left") {
4 @1 a6 ]: h% o' s# ~" Q
xPos = xPos - BallSpeed;
' d# E- O/ j- t ], m
}
" q/ K: K/ h7 {' ]# S: W
else {
, o: X- @7 x4 m9 ?
xPos = xPos;
! M- k- j2 `2 Q& ~ p0 \: Q1 p
}
! E! V* G3 X2 F5 P( }
if (yDir == "down") {
' p& _% n$ Q3 t+ L
yPos = yPos + BallSpeed;
4 b8 \* t: o. o. k; s2 Q. Y
}
, L( C- y3 m! |4 f( Z3 W
else if (yDir == "up") {
0 p$ @3 |& X$ I% k2 F% ^
yPos = yPos - BallSpeed;
' z/ q5 h# p7 v, Z$ U1 [. ?
}
9 d. I5 r4 ]( @% a& E R
else {
; T' m) ?* I" a
yPos = yPos;
1 p# G6 A, l) ]7 B- y7 O
}
; @( D; D8 c) [* w
}
% H6 O' L2 \5 d. y4 K }# e, r
1 o, {" X5 J" h0 S* \
function hidetext(){
2 Y7 x: J" c% G; ]! r
if (document.all)
$ z" |8 B& r" @) F9 j; m
supertext.style.visibility="hidden"
7 T; E0 e6 v. n
else if (document.layers)
3 ?. o' Z8 |- D
document.supertext.visibility="hide"
/ t/ k, y1 j& d
clearTimeout(animatetext)
& H H6 ]- d9 C k$ R0 ]7 a# G
}
7 R1 J; S4 Q. X- }! q/ k% f0 \1 u; }
9 q, O1 G/ ]0 o( I7 l. m! d! O2 o9 @
if (document.all||document.layers){
0 U$ s. S- q' F9 f- x
document.write('<span id="supertext"><nobr>'+thecontent+'</nobr></span>')
" Q$ b$ p- m8 X! b: Y5 _6 E3 `' ?
window.onload = initializeBall;
% i# A4 `7 d$ e+ W
window.onresize = new Function("window.location.reload()");
8 ~6 K! R, b5 i% w$ V% a
}
$ L; y8 Q: L3 O
) @1 a' ~, a, n2 T( n/ U
</script>
欢迎光临 捌玖网络工作室 (http://89w.org/)
Powered by Discuz! 7.2