模板:轮播图:修订间差异

来自黑神话百科
跳转到导航 跳转到搜索
无编辑摘要
无编辑摘要
标签手工回退
 
(未显示同一用户的4个中间版本)
第1行: 第1行:
<div class="carousel">
<div class="slider-container">
   <div class="carousel-images">
   <div class="slider" id="slider"></div>
    {{#ask: [[Category:Images]]
   <div class="arrow prev" id="sliderPrev"><</div>
      |?image
   <div class="arrow next" id="sliderNext">></div>
      |?link
   <div class="dots" id="dotsContainer"></div>
      |format=template
      |template=轮播图模板
      |limit=10
    }}
  </div>
   <div class="prev" onclick="moveSlide(-1)"><</div>
   <div class="next" onclick="moveSlide(1)">></div>
   <div class="indicators">
    {{#ask:[[Category:Images]]
      |format=template
      |template=指示器
      |limit=10
    }}
  </div>
</div>
</div>
{{#css:.carousel {
{{#Widget:轮播图}}
{{#css:
.slider-container {
   position: relative;
   position: relative;
  overflow: hidden;
   width: 100%;
   width: 100%;
  height: 300px;
}
}
.carousel-images {
.slider {
   display: flex;
   position: relative;
   transition: transform 0.5s ease;
   width: 100%;
  height: 469px;
  overflow: hidden;
}
}
.slide {
.slider img {
   min-width: 100%;
   opacity: 0;
   box-sizing: border-box;
  width: 100%;
   height: 100%;
  object-fit: cover;
  object-position: center;
  transition: opacity 700ms ease-in-out;
  position: absolute;
}
}
div.prev, div.next {
.arrow {
  cursor: pointer;
   position: absolute;
   position: absolute;
   top: 50%;
   top: 50%;
   transform: translateY(-50%);
   width: auto;
   background-color: rgba(255, 255, 255, 0.5);
  padding: 16px;
   border: none;
  margin-top: -22px;
   cursor: pointer;
  color: white;
  font-weight: bold;
   font-size: 18px;
  transition: 0.6s ease;
   border-radius: 0 3px 3px 0;
  user-select: none;
   -webkit-user-select: none;
}
.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}
 
.prev:hover, .next:hover {
  background-color: rgba(0, 0, 0, 0.8);
}
}
div.prev {
 
.dots {
  width: max-content;
  text-align: center;
  position: absolute;
   left: 0;
   left: 0;
}
div.next {
   right: 0;
   right: 0;
  bottom: 43px;
  margin: auto;
}
}
.indicator {
.dot {
  height: 12px;
  width: 94px;
  margin: 0 22px;
  background-color: #D9D9D9;
   display: inline-block;
   display: inline-block;
  width: 10px;
  height: 10px;
  margin: 5px;
  background-color: gray;
  border-radius: 50%;
   cursor: pointer;
   cursor: pointer;
  transition: background-color 0.6s ease;
}
.dot.active {
  background-color: #717171;
}
}
}}
}}
<includeonly>
<script type="text/javascript">
let currentSlide = 0;
function showSlide(index) {
  const slides = document.querySelectorAll('.slide');
  if(index >= slides.length) currentSlide = 0;
  if(index < 0) currentSlide = slides.length - 1;
  const offset = -currentSlide * 100;
  document.querySelector('.carousel-images').style.transform = `translateX(${offset}%)`;
}
function moveSlide(direction) {
  showSlide(currentSlide += direction);
}
showSlide(currentSlide);
</script>
</includeonly>

2024年8月18日 (日) 12:36的最新版本