我试图在我的网站标题上添加幻灯片,但是在最初加载时幻灯片没有显示,而是留下了点和箭头,但位置比应该的高。单击点或“下一页”箭头后,图像将正常显示,至少直到我到达幻灯片的末尾为止,然后图像将再次消失,箭头和点将“跳起来”。老实说,如果这是一个简单的问题,我很抱歉,我绝不是编码专家,我只是新手,碰壁了,经过两天的尝试/在这里搜索类似的问题,我想我最好问一下。任何帮助都表示赞赏!
<script>
var slideIndex = 1;
showSlides(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
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 = "none";
}
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";
}
</script>
* {box-sizing: border-box}
body {font-family: Verdana, sans-serif; margin:0}
.mySlides {display: none}
img {vertical-align: middle;}
/* Slideshow container */
.slideshow-container {
max-width: 740px;
position: relative;
margin: auto;
margin-top:76px;
}
/* Next & previous buttons */
.prev, .next {
cursor: pointer;
position: absolute;
top: 50%;
width: auto;
padding: 16px;
margin-left:-52px;
margin-top: -40px;
color: #792828;
font-weight: bold;
font-size: 30px;
transition: 0.6s ease;
border-radius: 0 3px 3px 0;
opacity: 0.5;
}
/* Position the "next button" to the right */
.next {
right: 0;
border-radius: 3px 0 0 3px;
left:800px;
}
/* Caption text */
.text {
color: #f2f2f2;
font-size: 15px;
padding: 8px 12px;
position: absolute;
bottom: 8px;
width: 100%;
text-align: center;
}
/* 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;
}
.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}
}
/* On smaller screens, decrease text size */
@media only screen and (max-width: 300px) {
.prev, .next,.text {font-size: 11px}
}
/* Town Info */
.towninfo {
height:260px;
width: 370px;
background-color: #101010;
border: 1px solid #0d0c0c;
margin-top:auto;
font-family: 'Constantia';
font-size: 10px;
text-align: center;
padding: 25px;
color:#958c8c;
display: inline-block;
}
.towninfo2 {
height:260px;
width: 370px;
background-color: #101010;
border: 1px solid #0d0c0c;
margin-top:auto;
font-family: 'Constantia';
font-size: 10px;
text-align: center;
padding: 25px;
color:#958c8c;
display: inline-block;
}
<div class="slideshow-container">
<div class="mySlides fade">
<img src="https://static.tumblr.com/uk6ur9p/5A9pbh7ft/middleimage.png" style="width:100%">
</div>
<div class="mySlides fade">
<img src="https://static.tumblr.com/uk6ur9p/C9Tpbh5fi/middleimage2.png" style="width:100%">
</div>
<div class="mySlides fade">
<div class="towninfo">Caption Three</div><div class="towninfo2">dfvdfdfdfdfdfdfdf</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>
答案 0 :(得分:0)
如果它们最后消失并“跳起来”,听起来像1)未设置预期数据(例如本例中的图像),2),因为使用了原始样式表css(显示:无;)。
我注意到您的第三张幻灯片是这样:
<div class="mySlides fade">
<div class="towninfo">Caption Three</div><div class="towninfo2">dfvdfdfdfdfdfdfdf</div>
</div>
而不是图像。您是否尝试过仅将其替换为其他两个图像,然后查看其是否正常工作?