<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript">
window.onload=function(){
var oImg=document.getElementById('img1')
var arrImgUrl=["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg"]
var num=0
function Tab(){
num++
if(num>arrImgUrl.length-1){
num=0
}
oImg.src=arrImgUrl[num]
}
setInterval(Tab,1000)
}
</script>
</head>
<body>
<img id="img1" src="img/1.jpg" width="288">
</body>
</html>
注意图片放在 名称为 img 的文件夹中,而且是格式的,否则需要修改html
function changeSrc(nIndex){var imageList = new Array()
imageList.push("1.jpg")
imageList.push("2.jpg")
var obj = document.getElementById("imagecontain")
obj.src = imageList[nIndex%imageList.length]
}
<div><img id="imagecontain" src="1.jpg" /></div>
<script>
var nIndex = 1
objTimer = window.setInterval(function(){
changeSrc(nIndex)
nIndex++
},1000)
document.getElementById("imagecontain").onmousemove = function(){
clearInterval(objTimer)
}
document.getElementById("imagecontain").onmouseout = function(){
objTimer = window.setInterval(function(){
changeSrc(nIndex)
nIndex++
},1000)
}
</script>
</body>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)