CSS:引用幻灯片中的幻灯片动画

时间:2021-01-14 09:22:02

标签: javascript css

我有一个简单的代码,它在点击幻灯片上发生变化。

我正在尝试在类“内容”的元素上制作动画,该元素可能看起来像 this animation

我在这段代码中尝试过,但看起来不太好。

是否有任何选项可以让我在上面发送的链接中为具有“内容”类的元素制作动画?

var slideIndex = 1;
showSlides(slideIndex);

function plusSlides(n) {
  showSlides(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].classList.remove("active");
  }
  for (i = 0; i < dots.length; i++) {
    dots[i].classList.remove("active");
  }
  slides[slideIndex - 1].classList.add("active");
  dots[slideIndex - 1].classList.add("active");
}
* {
  box-sizing: border-box;
}

body {
  font-family: Verdana, sans-serif;
  margin: 0;
}

/* Slideshow container */
.slideshow-container {
  height: 200px;
  position: relative;
  background: #f1f1f1f1;
}

/* Slides */
.mySlides {
  width: 100%;
  position: absolute;
  padding: 80px;
  text-align: center;
  visibility: hidden;
  transition: all 0s linear;
}
.mySlides .content {
  transition: all 0.2s;
  transform: translateX(-50px);
}
.mySlides.active {
  visibility: visible;
}
.mySlides.active .content {
  transform: translateX(0px);
}

/* Next & previous buttons */
.prev,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -30px;
  padding: 16px;
  color: #888;
  font-weight: bold;
  font-size: 20px;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

/* Position the "next button" to the right */
.next {
  position: absolute;
  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);
  color: white;
}

/* The dot/bullet/indicator container */
.dot-container {
  text-align: center;
  padding: 20px;
  background: #ddd;
}

/* 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;
}

/* Add a background color to the active dot/circle */
.dot.active,
.dot:hover {
  background-color: #717171;
}

/* Add an italic font style to all quotes */
q {
  font-style: italic;
}

/* Add a blue color to the author */
.author {
  color: cornflowerblue;
}
<div class="slideshow-container">

  <div class="mySlides">
    <div class="content">
      <q>I have not failed. I've just found 10,000 ways that won't work.</q>
      <p class=" author ">- Thomas A. Edison</p>
    </div>
  </div>

  <div class="mySlides">
    <div class="content">
      <q>But man is not made for defeat. A man can be destroyed but not defeated.</q>
      <p class=" author ">- Thomas A. Edison</p>
    </div>
  </div>

  <div class="mySlides">
    <div class="content">
      <q>I have not failed. I've just found 10,000 ways that won't work.</q>
      <p class=" author ">- Thomas A. Edison</p>
    </div>
  </div>



  <a class="prev " onclick="plusSlides(-1) ">❮</a>
  <a class="next " onclick="plusSlides(1) ">❯</a>

</div>

<div class="dot-container ">
  <span class="dot " onclick="currentSlide(1) "></span>
  <span class="dot " onclick="currentSlide(2) "></span>
  <span class="dot " onclick="currentSlide(3) "></span>
</div>

0 个答案:

没有答案