【发布时间】:2016-05-23 09:39:17
【问题描述】:
我决定尝试使用 CSS 中的动画为背景创建幻灯片,并使用 Javascript 中的第二层使用Jquery。
Javascript 运行正常,但 CSS 背景不正确。这是两者的代码。 Javascript 代码是从 W3Schools 的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
}
【问题讨论】:
-
它实际上不起作用
标签: javascript jquery css