怎样用javascript制作一个多幅图片切换特效,要求使用window对象的setTimeout()方法,代码简单一点
解决方案 »
- 如何排序字母和数字组合的
- 求助,JQuery改变<a>Hover的链接颜色
- scrollTop,scrollHeight js 等在不同浏览器的问题
- 如何把一个table里后面的一行整体赋给前面那行(innerHTML)
- DOM.setAttribute用法问题
- 求大神们 牛人们帮助啊,急急急
- javascript什么时候能支持import和export?
- 请教
- <script for=window event=onload>这样的用法在哪里可以查到?
- csdn评论的引用功能是怎么实现的
- 求一款非常酷炫的目录树代码,最好用JQERY实现的
- js能获得js本身的url吗?不是当前页面location.href,js在另一个域
<html>
<head>
<script type="text/javascript">
var c=0
var t
function timedCount()
{
if(c%2 == 0)
document.getElementById('pic').src="http://www.dosgd.com/images/pro_t/otop_logo.jpg";
else
document.getElementById('pic').src="http://www.aspxcs.net/UploadFiles/2010/6/201006020025306513.png";c=c+1
t=setTimeout("timedCount()",1000)
}
</script>
</head><body onload="timedCount()">
<div>
<img id="pic" src="http://www.aspxcs.net/UploadFiles/2010/6/201006020025306513.png">
</img>
</div>
</body></html>
三个图切换:c%3=0换src1, c%3=1换src2, c%3=2换src3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>广告切换!</title>
<style>
#dNum{
width:120px;
height:30px;
left:240px;
top:165px;
position:absolute;
}
td{
width:30px;
height:30px;
text-align:center;
vertical-align:middle;
font-size:18px;
font-family:"Times New Roman", Times, serif;
cursor:pointer;
}
.selectedNum{
background-color:#F00;
color:#FF0;
}
.normalNum{
background-color:#CCC;
color:#0F0;
}
</style>
<script>
window.onload=function(){
startCircle();
}function initImg(){
for(var i=1;i<=4;i++){
document.getElementById("img"+i).style.display="none";
document.getElementById("td"+i).className="normalNum";
}
}var index=1;
var timer;
function startCircle(){
initImg();
document.getElementById("img"+index).style.display="block";
document.getElementById("td"+index).className="selectedNum";
index++;
if(index>4)
index=1;
timer=setTimeout("startCircle()",2000);
}
function selectImg(ind){
clearTimeout(timer);
index=ind;
startCircle();
}
</script>
</head><body>
<img src="..." id="img1"/>
<img src="..." id="img2"/>
<img src="..." id="img3"/>
<img src="..." id="img4"/>
<div id="dNum">
<table width="120" cellpadding="0">
<tr>
<td id="td1" class="normalNum" onclick="selectImg(1)">1</td>
<td id="td2" class="normalNum" onclick="selectImg(2)">2</td>
<td id="td3" class="normalNum" onclick="selectImg(3)">3</td>
<td id="td4" class="normalNum" onclick="selectImg(4)">4</td></tr>
</table>
</div>
</body>
</html>