-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);
}
.header {
width: 100%;
height: 100px;
background-image: url("../background1.jpg");
text-align: center;
padding: 5px;
}
body {
margin: 0;
padding: 0;
background: white;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: deeppink;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover {
background-color: pink;
}
/*Slideshow container*/
.mySlides {
display: none
}
.slideshow-container {
max-width: 1000px;
position: relative;
margin: auto;
}
/*Next & previous buttons */
.prev,
.next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
margin-top: -22px;
padding: 16px;
color: white;
font-weight: bold;
font-size: 18px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
}
/* Position right next button */
.next {
right: 0;
border-radius: 3px 0 0 3px;
}
/* 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: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/*Number text*/
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/*The indicators*/
.dot {
cursor: pointer;
height: 13px;
width: 13px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.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
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Welcome to Fazbear Entertainment</title>
<link rel="stylesheet" href="css/fnaf.css" />
<script type="text/javascript" src="js/fnaf.js"></script>
</head>
<body bgcolor="#FFB6C1">
<div class="header">
</div>
<div id="nav">
<ul>
<li><a class="active" href="">Home</a>
</li>
<li><a href="">About</a>
</li>
<li><a href="">Contact</a>
</li>
<li><a href="">Prices</a>
</li>
</ul>
</div>
<div class="slideshow-container">
<div class="mySlides fade">
<div class="numbertext">1/5</div>
<img src="fnafworld.jpg" style="width:100%">
<div class="text">Welcome to Fazbear Entertainment</div>
</div>
<div class="mySlides fade">
<div class="numbertext">2/5</div>
<img src="funtimefreddy.png" style="width:100%">
<div class="text">Funtime Freddy</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3/5</div>
<img src="funtimefoxy.png" style="width:100%">
<div class="text">Funtime Foxy</div>
</div>
<div class="mySlides fade">
<div class="numbertext">4/5</div>
<img src="baby.jpg" style="width:100%">
<div class="text">Baby</div>
</div>
<div class="mySlides fade">
<div class="numbertext">5/5</div>
<img src="Ballora.png" style="width:100%">
<div class="text">Ballora</div>
</div>
<a class="prev" onClick="plusSlides(-1)">❮</a>
<a class="next" onClick="plusSlides(1)">❯</a>
</div>
<br>
<div style="text-align:center">
<span class="dot" onClick="currentSlide(1)"></span>
<span class="dot" onClick="currentSlide(2)"></span>
<span class="dot" onClick="currentSlide(3)"></span>
</div>
<br />
</body>
</html>
對不起這個有點漫長,但我真的想弄清楚的問題是什麼。非常感謝!
圖片沒有顯示出來可以有不同的原因。您的圖片src可能不正確。圖像可能不會出現在你指定的網址等等只是驗證你的圖像src。 – Manish