gpt4 book ai didi

javascript - 自动幻灯片放映不起作用

转载 作者:行者123 更新时间:2023-11-28 05:21:56 26 4
gpt4 key购买 nike

我想在 html 页面上放映幻灯片,并在 W3 网站上找到了 html/javascript 代码并复制了它。但它不起作用。我得到的只是显示为列表的 3 张图片。我一直在查看此处给出的有关该主题的一些答案,但仍然找不到问题所在。我认为代码已经完成并可以使用了。所以我需要一些帮助。代码如下:

javascript //自动幻灯片 - 每 3 秒更换一次图像 var slideIndex = 0; 显示幻灯片();

function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex> slides.length) {slideIndex = 1}
slides[slideIndex-1].style.display = "block";
setTimeout(showSlides, 3000);
}
the html
<!-- Slide Show section showing 3 img every 3 sec-->
<div class="slideshow-container">
<div class="mySlides fade">
<img class="mySlides" src="../images/Icons/sa.png" alt="a"
style="width:100%">
</div>
<div class="mySlides fade">
<img class="mySlides" src="../images/images/b.jpg" alt="b"
style="width:100%" >
</div>
<div class="mySlides fade">
<img class="mySlides" src="../images/images
/c.jpg" alt="c"
style="width:100%">
</div>

最佳答案

您需要 CSS,样式是使其发挥作用的重要组成部分。这是完整代码的链接:

http://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_slideshow_auto

<style>
* {box-sizing:border-box}
body {font-family: Verdana,sans-serif;}

/* Slideshow container */
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}

/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}

/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}

/* The dots/bullets/indicators */
.dot {
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}

.active {
background-color: #717171;
}

/* Fading animation */
.fade {
-webkit-animation-name: fade;
-webkit-animation-duration: 1.5s;
animation-name: fade;
animation-duration: 1.5s;
}

@-webkit-keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

@keyframes fade {
from {opacity: .4}
to {opacity: 1}
}

/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.text {font-size: 11px}
}
</style>

关于javascript - 自动幻灯片放映不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38983606/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com