我決定嘗試使用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
}
它實際上並不工作 –