[英]My image doesn't show until after my slideshow then when slideshow starts again, it disappears
我的图像直到我的幻灯片完成后才显示并且它立即消失它又重新开始,我个人认为是 JavaScript 的问题代码如下。
(HTML)
<h1 style="font-family: cursive; color: blue;">Jay<i style="color: pink;" class="fa fa-heart"></i>CeeZ</h1>
<div class="navbar">
<a class="active" href="#"><i class="fa fa-fw fa-home"></i> Home</a>
<a href="#"><i class="fas fa-file-alt"></i> News</a>
<a href="#"><i class="fa fa-fw fa-envelope"></i> Contact</a>
<a href="#"><i class="fa fa-fw fa-user"></i> About</a>
<a href="#" style="float: right; size: 25px; color:#ffffff;"><i onclick="myFunction()" class="fas fa-toggle-off"></i></a>
</div>
<div class="mySlides fade">
<div class="numbertext">1 / 3</div>
<img src="girl.jfif" style="width: 100%; height: 450px; ">
<div class="text-block">Up to 25% discount off women jacket <a href="women.html" style="text-decoration: none; background-color: red; width: 203;" >Shop Now!</a> </div>
</div>
<div class="mySlides fade">
<div class="numbertext">2 / 3</div>
<img src="boy.jfif" style="width: 100%; height: 450px;">
<div class="text-block">New Shirt Collection for Men <a href="men.html" style="text-decoration: none; background-color: red; width: 203;" >Shop Now!</a>
</div>
</div>
<div class="mySlides fade">
<div class="numbertext">3 / 3</div>
<img src="girl2.jfif" style="width: 100%;color: black; height: 450px; ">
<div class="text-block">Up to 15% discount for every first timer <a href="#collection" style="text-decoration: none; background-color: red; width: 203;" >Shop Now!</a></div>
<div>
</div>
<br>
<div style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
<br>
<h1>Women Rocks</h1>
<img src="girl.jfif" alt="first dress" width="203">
会不会是 HTML 因为我不明白? 所以这是下面的 CSS 代码。
(CSS)
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
<style>
body {font-family: Arial, Helvetica, sans-serif; overflow: scroll;}
.navbar {
width: 100%;
background-color: #555;
overflow: auto;
}
* {box-sizing: border-box;}
body {font-family: Verdana, sans-serif;}
.mySlides {display: none;}
img {vertical-align: middle;}
/* 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;
}
.text-block {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 25px;
color: #ffffff;
word-break: keep-all;
}
/* Number text (1/3 etc) */
.numbertext {
color: #f2f2f2;
font-size: 12px;
padding: 8px 12px;
position: absolute;
top: 0;
}
/* The dots/bullets/indicators */
.dot {
height: 15px;
width: 15px;
margin: 0 2px;
background-color: #bbb;
border-radius: 50%;
display: inline-block;
transition: background-color 0.6s ease;
}
.active {
background-color: #717171;
}
div.gallery {
border: 1px solid #ccc;
}
div.gallery:hover {
border: 1px solid #777;
}
div.gallery img {
width: 100%;
height: auto;
}
div.desc {
padding: 15px;
text-align: center;
}
* {
box-sizing: border-box;
}
.responsive {
padding: 0 6px;
float: left;
width: 24.99999%;
}
@media only screen and (max-width: 700px) {
.responsive {
width: 49.99999%;
margin: 6px 0;
}
}
@media only screen and (max-width: 500px) {
.responsive {
width: 100%;
}
}
.clearfix:after {
content: "";
display: table;
clear: both;
}
/* 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}
}
.navbar a {
float: left;
padding: 12px;
color: white;
text-decoration: none;
font-size: 17px;
}
.mySlides{
width: 100;
height: 50;
}
.navbar a:hover {
background-color: #000;
}
.active {
background-color: blue;
}
@media screen and (max-width: 500px) {
.navbar a {
float: none;
display: flexbox;
}
}
.dark-mode {
background-color: #000900;
color:red;
}
</style>
虽然 JS 很长,但我查看了它,但似乎没有问题,即使 CSS 看起来还不错,html 也很完美。
(JS)
function myFunction() {
var element = document.body;
element.classList.toggle("dark-mode");
}
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, 4000); // Change image every 2 seconds
}
</script>
第三张幻灯片的 div(带有 class mySlides)没有关闭标签( </div>
),因此它下面的元素将被视为最后一张幻灯片的内容,这就是它们会随之显示和消失的原因。 我认为第三个 mySlides 中 text-block 之后和</div>
之前的<div>
div> 可能是多余的,你可以去掉它再试一次。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.