写一段代码用js实现图片的轮播
时间: 2023-02-26 15:54:09 浏览: 121
JavaScript实现图片轮播特效
var myIndex = 0;
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
myIndex++;
if (myIndex > x.length) {myIndex = 1}
x[myIndex-1].style.display = "block";
setTimeout(carousel, 2000); // Change image every 2 seconds
}
阅读全文