示例:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
#bg_body{
background:url(1.jpg) no-repeat center #eee
background-attachment:fixed
height:1000px
}
</style>
<script type="text/javascript">
window.onload=function(){
var oBody=document.getElementById('bg_body')
var oS=oBody.style
function BgChenge(){
oS.backgroundImage='url(2.jpg)'
}
function BgPosition(){
oS.backgroundRepeat='no-repeat'
oS.backgroundPosition='center'
oS.backgroundAttachment='fixed'
}
function LoadMethod(){
BgChenge()
BgPosition()
}
setInterval(LoadMethod,1000)
}
</script>
</head>
<body id="bg_body">
</body>
</html>
如果有多张图片比如说1-10.jpg,那就把oS.backgroundImage='url(2.jpg)'改为oS.backgroundImage='url('+(parseInt(Math.random() * 10) + 1)+'.jpg)'
<!DOCTYPE html><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
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)