我在页面上有一个手动的幻灯片演示,但是我想在幻灯片演示控件上显示正确的图像顺序的同时向其中添加自动功能,我尝试修改Java脚本,但是我能做的最好的就是添加一个使用幻灯片显示控件之一后加快速度的计时器。
这是我的代码:
源代码:
<div class="w3-content w3-display-container container" style="max-width:800px; padding-top:5%">
<img class="mySlides" src="images/cheese.png" style="height:300px; width:800px">
<img class="mySlides" src="images/beverages.png" style="height:300px; width:800px">
<img class="mySlides" src="images/caramel2.png" style="height:300px; width:800px">
<div class="w3-center w3-container w3-section w3-large w3-text-white w3-display-bottommiddle" style="width:100%">
<div class="w3-left w3-hover-text-khaki" onclick="plusDivs(-1)">❮</div>
<div class="w3-right w3-hover-text-khaki" onclick="plusDivs(1)">❯</div>
<span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(1)"></span>
<span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(2)"></span>
<span class="w3-badge demo w3-border w3-transparent w3-hover-white" onclick="currentDiv(3)"></span>
</div>
</div>
CSS:
.w3-tooltip,.w3-display-container{position:relative}.w3-tooltip .w3-text{display:none}.w3-tooltip:hover .w3-text{display:inline-block}
.w3-display-container:hover .w3-display-hover{display:block}.w3-display-container:hover span.w3-display-hover{display:inline-block}.w3-display-hover{display:none}
.w3-left-align{text-align:left!important}.w3-right-align{text-align:right!important}.w3-justify{text-align:justify!important}.w3-center{text-align:center!important}
.w3-container:after,.w3-container:before,.w3-panel:after,.w3-panel:before,.w3-row:after,.w3-row:before,.w3-row-padding:after,.w3-row-padding:before,
.w3-container,.w3-panel{padding:0.01em 16px}.w3-panel{margin-top:16px;margin-bottom:16px}
.w3-section,.w3-code{margin-top:16px!important;margin-bottom:16px!important}
.w3-tiny{font-size:10px!important}.w3-small{font-size:12px!important}.w3-medium{font-size:15px!important}.w3-large{font-size:18px!important}
.w3-text-white,.w3-hover-text-white:hover{color:#fff!important}
.w3-display-bottommiddle{position:absolute;left:50%;bottom:0;transform:translate(-50%,0%);-ms-transform:translate(-50%,0%)}
.w3-left{float:left!important}.w3-right{float:right!important}
.w3-text-khaki,.w3-hover-text-khaki:hover{color:#b4aa50!important}
.w3-badge,.w3-tag{background-color:#000;color:#fff;display:inline-block;padding-left:8px;padding-right:8px;text-align:center}.w3-badge{border-radius:50%}
.w3-border-0{border:0!important}.w3-border{border:1px solid #ccc!important}
.w3-border-top{border-top:1px solid #ccc!important}.w3-border-bottom{border-bottom:1px solid #ccc!important}
.w3-border-left{border-left:1px solid #ccc!important}.w3-border-right{border-right:1px solid #ccc!important}
.w3-transparent,.w3-hover-none:hover{background-color:transparent!important}
.w3-white,.w3-hover-white:hover{color:#000!important;background-color:#fff!important}
.mySlides {display:none}
.w3-left, .w3-right, .w3-badge {cursor:pointer}
.w3-badge {height:13px;width:13px;padding:0}
Java脚本:
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";
}
P.S:该代码不是我的,我使用了https://www.w3schools.com/w3css/tryit.asp?filename=tryw3css_slideshow_dots2
中的代码答案 0 :(得分:0)
我认为这背后的想法是在创建计时器之后,您应该将其时间存储在变量中,例如如果它是10 s,它将保存在变量中,然后您将在js事件中执行操作,例如当它击中十分之一秒时显示下一张图片,我认为如果使用vue.js Framework bcs会很容易,它具有show命令,并且可以将其设置为true或false,所以您将在第十秒执行一个警告框,如果用户单击yes,那么节目将是真实的,不幸的是下一张照片会出现,我暂时无法给您提供稳定的密码