网站首页图片动态更换显示【Javascript】

      以前写过一篇网站首页图片动态更换显示【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<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<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">&nbsp;</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<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<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">&nbsp;</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<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<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">&nbsp;</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<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<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">&nbsp;</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<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<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">&nbsp;</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">
 79var nn;
 80nn=2;
 81setTimeout('change_img()',2000);
 82function change_img()
 83{
 84if(nn>5) nn=1
 85setTimeout('setFocus1('+nn+')',4000);
 86nn++;
 87tt=setTimeout('change_img()',4000);
 88}

 89function setFocus1(i)
 90{
 91selectLayer1(i);
 92}

 93function selectLayer1(i)
 94{
 95switch(i)
 96{
 97case 1:
 98document.getElementById("focusPic1").style.display="block";
 99document.getElementById("focusPic2").style.display="none";
100document.getElementById("focusPic3").style.display="none";
101document.getElementById("focusPic4").style.display="none";
102document.getElementById("focusPic5").style.display="none";
103break;
104case 2:
105document.getElementById("focusPic1").style.display="none";
106document.getElementById("focusPic2").style.display="block";
107document.getElementById("focusPic3").style.display="none";
108document.getElementById("focusPic4").style.display="none";
109document.getElementById("focusPic5").style.display="none";
110break;
111case 3:
112document.getElementById("focusPic1").style.display="none";
113document.getElementById("focusPic2").style.display="none";
114document.getElementById("focusPic3").style.display="block";
115document.getElementById("focusPic4").style.display="none";
116document.getElementById("focusPic5").style.display="none";
117break;
118case 4:
119document.getElementById("focusPic1").style.display="none";
120document.getElementById("focusPic2").style.display="none";
121document.getElementById("focusPic3").style.display="none";
122document.getElementById("focusPic4").style.display="block";
123document.getElementById("focusPic5").style.display="none";
124break;
125case 5:
126document.getElementById("focusPic1").style.display="none";
127document.getElementById("focusPic2").style.display="none";
128document.getElementById("focusPic3").style.display="none";
129document.getElementById("focusPic4").style.display="none";
130document.getElementById("focusPic5").style.display="block";
131break;
132}

133}

134
</SCRIPT>
135</html>
原文地址:https://www.cnblogs.com/xpengfee/p/789725.html