【发布时间】:2018-07-09 01:49:20
【问题描述】:
我正在尝试在我的网站标题上添加幻灯片,但在最初加载幻灯片时没有显示,而是留下了点和箭头,但位置比应有的位置高得多。在我点击一个点或“下一页”箭头后,图像会正常显示,至少直到我到达幻灯片的末尾,然后图像会再次消失,箭头和点会“跳起来”。如果这是一个简单的问题,我真的很抱歉,我绝不是编码方面的专业人士,我只是一个新手,我碰壁了,经过两天我自己的尝试/在这里搜索类似的问题,我想我不妨问问。任何帮助都将不胜感激!
<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>
【问题讨论】:
标签: javascript html css slider slideshow