尝试使用W3.CSS制作幻灯片,这是我的新功能,所以我不确定我做错了什么,每个元素都可以自己运行,就像图像指示器一样图像标题,但是当它们像这样放在一起时,由于某种原因它们会搞乱。
我在这里缺少什么,或者代码没有办法像这样工作?
<!--slideshow stuff-->
<!--image headings-->
<div class="w3-display-container mySlides">
<img src="pcexclusives.jpg" alt="pcexclusives" style="width:100%" height="768" width="1366">
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">
</div>
</div>
<div class="w3-display-container mySlides">
<img src="battlefieldV.jpg" style="width:100%" height="768" width="1366">
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">
</div>
</div>
<div class="w3-display-container mySlides">
<img src="bethesdaes6.jpg" style="width:100%" height="768" width="1366">
<div class="w3-display-topmiddle w3-container w3-padding-16 w3-white">
</div>
</div>
<!--image indicator-->
<div class="w3-content w3-display-container">
<div class="w3-center w3-display-bottommiddle" style="width:100%">
<div class="w3-left" onclick="plusDivs(-1)">❮</div>
<div class="w3-right" onclick="plusDivs(1)">❯</div>
<span class="w3-badge demo w3-border" onclick="currentDiv(1)"></span>
<span class="w3-badge demo w3-border" onclick="currentDiv(2)"></span>
<span class="w3-badge demo w3-border" onclick="currentDiv(3)"></span>
</div>
</div>
<script>
var slideIndex = 0;
carousel();
function carousel() {
var i;
var x = document.getElementsByClassName("mySlides");
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, 4000); // Change image every 4 seconds
}
</script>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length} ;
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("demo");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" w3-white", "");
}
x[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " w3-white";
}
</script>
&#13;