【问题标题】:slideshow not initially appearing幻灯片最初没有出现
【发布时间】: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)">&#10094;</a>
<a class="next" onclick="plusSlides(1)">&#10095;</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


    【解决方案1】:

    如果它们最终消失并“跳起来”,这听起来像是 1)没有设置预期数据(例如本例中的图像)和 2)因为使用了原始样式表 css(显示:无;)。

    我注意到你的第三张幻灯片是这样的:

    <div class="mySlides fade">
      <div class="towninfo">Caption Three</div><div class="towninfo2">dfvdfdfdfdfdfdfdf</div>
    </div>
    

    而不是图像。您是否尝试过仅将其替换为其他两个图像并查看其是否正常工作?

    【讨论】:

    • 我认为可能是这种情况,但据我所知,没有空滑块。 “显示:无”确实使图像显示出来......但它们同时出现在彼此下方,这并不是完全可取的。也是的!我认为这也可能是问题,但是用图像替换它不起作用,问题仍然存在。一旦我实际单击箭头或项目符号并使其工作,它在幻灯片放映期间也会正常显示。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 2019-09-20
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多