以前写过一篇网站首页图片动态更换显示【Flash】 ,主要是介绍了一下网站首页常见的图片新闻更换程序。今天上网发现一个用Javascript脚本写的,效果也很是不错,来看一下:
跟Flash版的几乎一样,看一下代码吧,主要是JS:
1
<html>
2
<head>
3
<style>DIV.dLocBBS { PADDING-LEFT: 17px; FLOAT: left; PADDING-BOTTOM: 3px; WIDTH: 20.2%; PADDING-TOP: 3px }
4
.ImgChange1 { FONT-WEIGHT: bold; FONT-SIZE: 12px; WIDTH: 100%; LINE-HEIGHT: 20px; TEXT-ALIGN: center }
5
.LinkTD{ padding-top:10px;padding-right:20px;}
6
</style>
7
</head>
8
<div class="ImgChange1" id="focusPic1" style="display:block">
9
<a href="http://www.8spaces.com/bbs/40100/20414.html" target="_blank"><img width="370" height="222" border="0" alt="加州私人海滩随拍,美女眼花缭乱,应接不暇" src="http://www.8spaces.com/hpic/2007/6/1/b438669d-c8be-4ebd-ac53-c2748a6103b7.jpg" /><br /></a>
10
<a href="http://www.8spaces.com/bbs/40100/20414.html" target="_blank">加州私人海滩随拍,美女眼花缭乱,应接不暇</a>
11
<table width="98.5%" border="0" cellpadding="0" cellspacing="1" align="center" style="margin:auto;clear:both;">
12
<tr align="center">
13
<td bgcolor="#ebebeb"> </td>
14
<td width="26" style="color:#FFFFFF;" bgcolor="#0049A5">1</td>
15
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(2)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">2</td>
16
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(3)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">3</td>
17
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(4)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">4</td>
18
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(5)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">5</td>
19
</tr>
20
</table>
21
</div>
22
<div class="ImgChange1" id="focusPic2" style="display:none">
23
<a href="http://www.8spaces.com/bbs/40101/19941.html" target="_blank"><img width="370" height="222" border="0" alt="梦寻香港电影拍摄场地,香港新况小记" src="http://www.8spaces.com/hpic/2007/6/1/e79b8456-fcb2-4e14-b48c-a8b7f9f2757d.jpg" /><br /></a>
24
<a href="http://www.8spaces.com/bbs/40101/19941.html" target="_blank">梦寻香港电影拍摄场地,香港新况小记</a>
25
<table width="98.5%" border="0" cellpadding="0" cellspacing="1" align="center" style="margin:auto;clear:both;">
26
<tr align="center">
27
<td bgcolor="#ebebeb"> </td>
28
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(1)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">1</td>
29
<td width="26" style="color:#FFFFFF;" bgcolor="#0049A5">2</td>
30
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(3)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">3</td>
31
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(4)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">4</td>
32
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(5)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">5</td>
33
</tr>
34
</table>
35
</div>
36
<div class="ImgChange1" id="focusPic3" style="display:none">
37
<a href="http://www.8spaces.com/bbs/40103/20367.html" target="_blank"><img width="370" height="222" border="0" alt="北美车展花拍,看外国车展之差异" src="http://www.8spaces.com/hpic/2007/6/1/141e1dc0-1f70-48a3-83a0-5ffc1abc43fc.jpg" /><br /></a>
38
<a href="http://www.8spaces.com/bbs/40103/20367.html" target="_blank">北美车展花拍,看外国车展之差异</a>
39
<table width="98.5%" border="0" cellpadding="0" cellspacing="1" align="center" style="margin:auto;clear:both;">
40
<tr align="center">
41
<td bgcolor="#ebebeb"> </td>
42
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(1)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">1</td>
43
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(2)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">2</td>
44
<td width="26" style="color:#FFFFFF;" bgcolor="#0049A5">3</td>
45
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(4)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">4</td>
46
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(5)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">5</td>
47
</tr>
48
</table>
49
</div>
50
<div class="ImgChange1" id="focusPic4" style="display:none">
51
<a href="http://www.8spaces.com/bbs/40103/20462.html" target="_blank"><img width="370" height="222" border="0" alt="传统民俗图文详解,你知道的有几个?" src="http://www.8spaces.com/hpic/2007/6/1/6a9b1fc2-baf7-4772-b903-6a7b8bab7b6b.jpg" /><br /></a>
52
<a href="http://www.8spaces.com/bbs/40103/20462.html" target="_blank">传统民俗图文详解,你知道的有几个?</a>
53
<table width="98.5%" border="0" cellpadding="0" cellspacing="1" align="center" style="margin:auto;clear:both;">
54
<tr align="center">
55
<td bgcolor="#ebebeb"> </td>
56
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(1)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">1</td>
57
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(2)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">2</td>
58
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(3)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">3</td>
59
<td width="26" style="color:#FFFFFF;" bgcolor="#0049A5">4</td>
60
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(5)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">5</td>
61
</tr>
62
</table>
63
</div>
64
<div class="ImgChange1" id="focusPic5" style="display:none">
65
<a href="http://www.8spaces.com/bbs/40101/19714.html" target="_blank"><img width="370" height="222" border="0" alt="五月世界新闻图片精选,静观世界前亭落燕" src="http://www.8spaces.com/hpic/2007/6/1/2bfe9a5b-53de-45fa-89b9-8dec9c0ecdf6.jpg" /><br /></a>
66
<a href="http://www.8spaces.com/bbs/40101/19714.html" target="_blank">五月世界新闻图片精选,静观世界前亭落燕</a>
67
<table width="98.5%" border="0" cellpadding="0" cellspacing="1" align="center" style="margin:auto;clear:both;">
68
<tr align="center">
69
<td bgcolor="#ebebeb"> </td>
70
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(1)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">1</td>
71
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(2)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">2</td>
72
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(3)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">3</td>
73
<td width="26" bgcolor="#9EC9EC" style="cursor:pointer" onclick="javascript:setFocus1(4)" onmouseover="this.style.color='#FFFFFF';this.style.backgroundColor='#0049A5'" onmouseout="this.style.color='#004AA7';this.style.backgroundColor='#9EC9EC'">4</td>
74
<td width="26" style="color:#FFFFFF;" bgcolor="#0049A5">5</td>
75
</tr>
76
</table>
77
</div>
78
<SCRIPT language="javascript">
79
var nn;
80
nn=2;
81
setTimeout('change_img()',2000);
82
function change_img()
83
{
84
if(nn>5) nn=1
85
setTimeout('setFocus1('+nn+')',4000);
86
nn++;
87
tt=setTimeout('change_img()',4000);
88
}
89
function setFocus1(i)
90
{
91
selectLayer1(i);
92
}
93
function selectLayer1(i)
94
{
95
switch(i)
96
{
97
case 1:
98
document.getElementById("focusPic1").style.display="block";
99
document.getElementById("focusPic2").style.display="none";
100
document.getElementById("focusPic3").style.display="none";
101
document.getElementById("focusPic4").style.display="none";
102
document.getElementById("focusPic5").style.display="none";
103
break;
104
case 2:
105
document.getElementById("focusPic1").style.display="none";
106
document.getElementById("focusPic2").style.display="block";
107
document.getElementById("focusPic3").style.display="none";
108
document.getElementById("focusPic4").style.display="none";
109
document.getElementById("focusPic5").style.display="none";
110
break;
111
case 3:
112
document.getElementById("focusPic1").style.display="none";
113
document.getElementById("focusPic2").style.display="none";
114
document.getElementById("focusPic3").style.display="block";
115
document.getElementById("focusPic4").style.display="none";
116
document.getElementById("focusPic5").style.display="none";
117
break;
118
case 4:
119
document.getElementById("focusPic1").style.display="none";
120
document.getElementById("focusPic2").style.display="none";
121
document.getElementById("focusPic3").style.display="none";
122
document.getElementById("focusPic4").style.display="block";
123
document.getElementById("focusPic5").style.display="none";
124
break;
125
case 5:
126
document.getElementById("focusPic1").style.display="none";
127
document.getElementById("focusPic2").style.display="none";
128
document.getElementById("focusPic3").style.display="none";
129
document.getElementById("focusPic4").style.display="none";
130
document.getElementById("focusPic5").style.display="block";
131
break;
132
}
133
}
134
</SCRIPT>
135
</html>

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135
