我决定尝试使用Jquery
使用CSS中的背景用第二层Javascript创建幻灯片。在CSS中使用背景颜色变化的JS幻灯片
Javascript运行正常,但CSS背景不正确。这是两者的代码。该代码是从W3School的'Automatic Slideshow example借来的。
CSS:
body {
animation-name: change_color; animation-duration: 10s;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite;
}
@keyframes change_color {
{ from (0%) }
{ to (100%) }
}
的Javascript:
var slideIndex = 0;
carousel();
function carousel() {
var i = 0;
var x = document.getElementsByClassName("a");
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
slideIndex++;
if (slideIndex > x.length) {
slideIndex = 1
}
x[slideIndex - 1].style.display = "block";
setTimeout(carousel, 10000); // Change image every 2 seconds
}
它实际上并不工作 –