gpt4 book ai didi

javascript - 这个图像 slider 什么也没有开始,为什么?

转载 作者:行者123 更新时间:2023-11-28 19:11:01 25 4
gpt4 key购买 nike

所以我为一个学校元素制作了一个图像 slider ,当我启动页面或重新加载它时就会发生这种情况。该页面仅显示箭头和点。 Screenshot of the problem

这是我的代码:

showSlides(slideIndex);

// Next/previous controls
function plusSlides(n) {
showSlides(slideIndex += n);
}

// Thumbnail image controls
function currentSlide(n) {
showSlides(slideIndex = n);
}

function showSlides(n) {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
if (n > slides.length) {
slideIndex = 1
}
if (n < 1) {
slideIndex = slides.length
}
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "block";
}
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";
}
margin-top: -8px;
margin-left: -8px;

}
.header {
margin-top: 25px;
}
.headerimg {
width: 2047px;
margin-bottom: -168px;
}
.toDHL {
color: red;
margin-left: 81px;
}
.menu-bar {
color: black;
text-decoration: none;
font-size: 35px;
font-family: Arial;
font-weight: bold;
}
.linkimg {
width: 537px;
height: 150px;
margin-top: -89px;
margin-left: 17px;
}
#toHome {
margin-left: 50px;
border-bottom: 3px solid red;
}
#toRooster {
margin-left: 200px;
}
#toSmoelenboek {
margin-left: 200px;
}
#toSuccesverhaal {
margin-left: 200px;
position: absolute;
}
.slideshow-container {
float: left;
}
* {
box-sizing: border-box
}

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

/* Hide the images by default */
.mySlides {
display: none;
}

/* Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: black;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
user-select: none;
}

/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
margin-right: 0px;
}

/* On hover, add a black background color with a little bit see-through */
.prev:hover,
.next:hover {
background-color: rgba(0, 0, 0, 0.8);
}

/* Caption text */
.text {
color: #f2f2f2;
font-size: 50px;
padding: 8px 5px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
text-shadow: 2px 2px #000000;
}

/* The dots/bullets/indicators */
.dot {
cursor: pointer;
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
margin-top: 660px;
}
.active,
.dot:hover {
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
}
}
.Succesverhalen_Sidebar {
float: right;
margin-left: 15px;
margin-top: 30px;
}
.Succesverhalen_Sidebar_text {
position: absolute;
margin-left: 1900px;
margin-top: 91px;
}
<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/home.css">
<script src="JavaScript/home.js"></script>
<title>DHL Nieuws</title>
</head>
<header>
<img src="images/HeaderDHL.png" alt="header" class="headerimg">
<a href="https://www.logistics.dhl/nl-nl/home.html" target="_blank"><img src="images/banner-wave-3.svg" class="linkimg"></a>
<meta name="viewport" content="width=device-width, initial-scale=1">
</header>

<body>
<div class="header">
<a href="/home.html" class="menu-bar" id="toHome">Home</a>
<a href="Rooster/rooster.html" class="menu-bar" id="toRooster">Rooster</a>
<a href="Smoelenboek/smoelenboek.html" class="menu-bar" id="toSmoelenboek">Smoelenboek</a>
<a href="Succesverhalen/succesverhalen.html" class="menu-bar" id="toSuccesverhaal">Succesverhalen</a>
</div>
<!-- Slideshow container -->
<div class="slideshow-container">

<!-- Full-width images with number and caption text -->
<div class="mySlides fade">
<img src="images/Sinterklaas_news.jpg" style="width:100%">
<div class="text">Sinterklaas is weer in het land!</div>
</div>

<div class="mySlides fade">
<img src="images/BlackFriday_news.jpg" style="width:100%">
<div class="text">Het is binnen kort Black Friday!</div>
</div>

<div class="mySlides fade">
<img src="images/kerst.jpg" style="width:100%">
<div class="text">Santa Claus is coming to town!</div>
</div>

<!-- Next and previous buttons -->
<a class="prev" onclick="plusSlides(-1)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</a>
</div>
<br>

<!-- The dots/circles -->
<div>
<span class="dot" onclick="currentSlide(1)"></span>
<span class="dot" onclick="currentSlide(2)"></span>
<span class="dot" onclick="currentSlide(3)"></span>
</div>
<div class="Succesverhalen_Sidebar">
<img src="../images/Succesverhalen_Sidebar.png" style="margin-right:-279px;">
</div>
<div class="Succesverhalen_Sidebar_text">
<p>.........................<br>.........................<br>.........................
<br>.........................<br>......<a href="../Succesverhalen/succesverhalen.html">Lees verder</a></p>
<br>
<br>
<br>
<p>.........................<br>.........................<br>.........................
<br>.........................<br>......<a href="../Succesverhalen/succesverhalen.html">Lees verder</a></p>
<br>
<br>
<p>.........................<br>.........................<br>.........................
<br>.........................<br>......<a href="../Succesverhalen/succesverhalen.html">Lees verder</a></p>
<br>
<br>
<p>.........................<br>.........................<br>.........................
<br>.........................<br>......<a href="../Succesverhalen/succesverhalen.html">Lees verder</a></p>
<br>
<br>
<p>.........................<br>.........................<br>.........................
<br>.........................<br>......<a href="../Succesverhalen/succesverhalen.html">Lees verder</a></p>
<br>
<br>
<br>
<p>.........................<br>.........................<br>.........................
<br>.........................<br>......<a href="../Succesverhalen/succesverhalen.html">Lees verder</a></p>
<br>
<br>
<p>.........................<br>.........................<br>.........................
<br>.........................<br>......<a href="../Succesverhalen/succesverhalen.html">Lees verder</a></p>

</div>

</body>

</html>

我希望尽快收到答复,因为该元素的截止日期还有几天就要结束了。谢谢。

A screenshot of my the console.

最佳答案

你只需要定义 slideIndex 就像 var slideIndex=0;或 =1 所以它将是 var slideIndex = 1;
显示幻灯片(幻灯片索引);并且 javascript 没有正确加载,因为它在头部所以把脚本标签放在 body 的底部

关于javascript - 这个图像 slider 什么也没有开始,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59308009/

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