方法一:
用一个 setInterval套几个settimeout实现
代码如下:
setInterval(function(){
setTimeout(function () {
img.src="gallery-img2.png";
},500);
setTimeout(function () {
img.src="gallery-img3.png";
},1000);
setTimeout(function () {
img.src="gallery-img1.png";
},1500);
},1500);
方法二:
把图片放在数组中,再循环播放
代码如下:
var tupian=["gallery-img1.png","gallery-img2.png","gallery-img3.png"];
var i=1;
function change(){
img.src=tupian[i];
i++;
if(i>=tupian.length){
i=0;
}
}
setInterval(change,1000);