<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
一般是用脚本实现。示例:<!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>你背景图片就设置了一个2.jpg再切换也是这一张图片啊如果有多张图片比如说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">
<!-- TemplateBeginEditable name="doctitle" -->
<title>我的图片</title>
</head>
<body>
<canvas id="Map" width="500" height="500" style="background:gray"></canvas>
<script>
// 设置绘图环境
var myMap = document.getElementById("Map")
var cxt = myMap.getContext('2d')
// 设置图像位置初始位置的变量
var x = 20
var y = 20
// 创建绘图对象,并且画出来
var img = new Image()
img.src = "img/u55.png"
draw()
function draw() {
cxt.clearRect(0, 0, 500, 500)
x += 1
y += 5
cxt.drawImage(img, x, y, 80, 80)
}
window.setInterval(draw, 100)
</script>
</body>
</html>
你把图片的路径改为你的图片路径就行了!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)