我正在尝试制作一个使用JavaScript循环显示3个图像的横幅.
在更改之前,每张图像应显示10秒钟.
我写了一些代码,但它没有用.它一直停留在第一张图像上.图像不会像我想要的那样改变.
你能看到代码中的任何内容并指出我的错误吗?
代码如下:
<script type="text/javascript">
function changeBanner(){
var img = new array
img[0] = document.images[0].src
img[1] = document.images[1].src
img[2] = document.images[2].src
var currentimg = img[0]
if(currentimg == img[0]) {
currentimg = img[1]
}
if(currentimg == img[1]) {
currentimg = img[2]
}
}
</script>
Run Code Online (Sandbox Code Playgroud)
HTML如下:
<body onload="var start=setInterval('changeBanner()', 10000;">
<div id="wrapper">
<div>
<img src="budda.JPG" width="900px" height="300px" />
</div>
...
Run Code Online (Sandbox Code Playgroud)
var index = 0;
function changeBanner() {
[].forEach.call(document.images, function(v, i) {
document.images[i].hidden = i !== index
});
index = (index + 1) % document.images.length;
}
window.onload = function() {
setInterval(changeBanner, 1000)
};
Run Code Online (Sandbox Code Playgroud)
http://jsbin.com/emilef/2/edit
| 归档时间: |
|
| 查看次数: |
27014 次 |
| 最近记录: |