gpt4 book ai didi

javascript - 如何让幻灯片在移动到下一张幻灯片之前持续很长时间,以及如何将圆点向上移动到幻灯片的左上角

转载 作者:行者123 更新时间:2023-11-28 02:24:12 24 4
gpt4 key购买 nike

我有两个问题:

  1. 如何让幻灯片持续更长时间,然后再转到下一张,因为目前它只持续约 1 秒。我搞砸了以下行

setTimeout(showSlides, 2000);//每 2 秒更换一次图像

但所做的只是将其设置为从一张幻灯片移动到另一张幻灯片的某种延迟。在我想要的位置,它停留在 1 号幻灯片上,他们等待大约 10 秒左右,然后移到 2 号幻灯片上。

  1. 当我将边距更改为负数时,如何将指示点移动到幻灯片的左上角,但这只会完全弄乱这些点。

如上所述,IO 更改了以下行:

setTimeout(showSlides, 2000);//每 2 秒更换一次图像

并更改边距,但什么也没有。

以下代码适用于 Q1 和 2。

var slideIndex = 0;
showSlides();

function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
* {
box-sizing: border-box;
}

body {
font-family: Verdana, sans-serif;
}

.mySlides {
display: none;
}

img {
vertical-align: middle;
}


/* Slideshow container */

.slideshow-container {
max-width: 100%;
position: relative;
margin: auto;
padding-left: 25px;
padding-right: 25px;
}


/* Caption text */

.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: laft;
background-color: #000;
width: 150px;
margin-left: 15px;
}


/* The dots/bullets/indicators */

.dot {
height: 15px;
width: 15px;
margin: 0px 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
float: left;
}

.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
}
}
My HTML Is:

<div class="slideshow-container">

<div class="mySlides fade">
<img src="img/1.jpg" style="width:100%">
<div class="text">Caption Text</div>
</div>

<div class="mySlides fade">
<img src="img/1.jpg" style="width:100%">
<div class="text">Caption Two</div>
</div>

<div class="mySlides fade">
<img src="img/1.jpg" style="width:100%">
<div class="text">Caption Three</div>
</div>

</div>
<br>

<div style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>

这是幻灯片的屏幕截图,其中标明了我希望圆点所在的位置。

https://imgur.com/EiC4vSu

感谢任何帮助并提前感谢您

最佳答案

问题 1:

在触发下一张图片之前将下面的更改为“等待”

setTimeout(showSlides, 5000); // Change image every 5 seconds

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout

如果您希望图像之间的过渡有一些延迟,请更改淡入淡出动画级别

-webkit-animation-duration: 2s;

animation-duration: 2s;

问题 2:

只需将您的点 div 移动到容器 div 之前

var slideIndex = 0;
showSlides();

function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex > slides.length) {
slideIndex = 1
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex - 1].style.display = "block";
dots[slideIndex - 1].className += " active";
setTimeout(showSlides, 5000); // Change image every 2 seconds
}
* {
box-sizing: border-box;
}

body {
font-family: Verdana, sans-serif;
}

.mySlides {
display: none;
}

img {
vertical-align: middle;
}


/* Slideshow container */

.slideshow-container {
max-width: 100%;
position: relative;
margin: auto;
padding-left: 25px;
padding-right: 25px;
}


/* Caption text */

.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: laft;
background-color: #000;
width: 150px;
margin-left: 15px;
}


/* The dots/bullets/indicators */

.dot {
height: 15px;
width: 15px;
margin: 0px 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
float: left;
}

.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
}
}
My HTML Is:
<div style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
<div class="slideshow-container">

<div class="mySlides fade">
<img src="https://www.mediawiki.org/static/images/project-logos/mediawikiwiki.png" style="width:100%">
<div class="text">Caption Text</div>
</div>

<div class="mySlides fade">
<img src="https://www.mediawiki.org/static/images/project-logos/mediawikiwiki.png" style="width:100%">
<div class="text">Caption Two</div>
</div>

<div class="mySlides fade">
<img src="https://www.mediawiki.org/static/images/project-logos/mediawikiwiki.png" style="width:100%">
<div class="text">Caption Three</div>
</div>

</div>

关于javascript - 如何让幻灯片在移动到下一张幻灯片之前持续很长时间,以及如何将圆点向上移动到幻灯片的左上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55423319/

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