模板:轮播图:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
第1行: | 第1行: | ||
<div class=" | <div class="slider-container"> | ||
<div class=" | <div class="slider" id="slider"></div> | ||
<div class="arrow prev" onclick="prevSlide()"><</div> | |||
<div class="arrow next" onclick="nextSlide()">></div> | |||
<div class="dots" id="dotsContainer"></div> | |||
<div class="prev" onclick=" | |||
<div class="next" onclick=" | |||
<div class=" | |||
</div> | </div> | ||
{{#css:. | <includeonly> | ||
<script type="text/javascript"> | |||
let slider = document.getElementById('slider'); | |||
let dotsContainer = document.getElementById('dotsContainer'); | |||
let currentSlide = 0; | |||
function createSlider(images, links) { | |||
images.forEach((obj, index) => { | |||
let img = document.createElement('img'); | |||
img.src = obj.src; | |||
img.style.opacity = index === 0 ? 1 : 0; | |||
img.onclick = () => window.open(obj.link, '_blank'); | |||
slider.appendChild(img); | |||
let dot = document.createElement('span'); | |||
dot.className = 'dot'; | |||
dot.onclick = () => jumpToSlider(index); | |||
dotsContainer.appendChild(dot); | |||
}); | |||
dotsContainer.children[0].classList.add('active'); | |||
setInterval(() => { | |||
nextSlide(); | |||
}, 1000 * 5) | |||
} | |||
function updateSlider() { | |||
Array.from(slider.children).forEach((slide, index) => { | |||
slide.style.opacity = index === currentSlide ? 1 : 0; | |||
}); | |||
Array.from(dotsContainer.children).forEach((dot, index) => { | |||
dot.classList.toggle('active', index === currentSlide); | |||
}); | |||
} | |||
function nextSlide() { | |||
currentSlide = (currentSlide + 1)%images.length; | |||
updateSlider(); | |||
} | |||
function prevSlide() { | |||
currentSlide = (currentSlide - 1 + images.length)%images.length; | |||
updateSlider(); | |||
} | |||
function jumpToSlider(slideIndex) { | |||
currentSlide = slideIndex; | |||
updateSlider(); | |||
} | |||
</script> | |||
</includeonly> | |||
{{#css: | |||
.slider-container { | |||
position: relative; | position: relative; | ||
width: 100%; | width: 100%; | ||
} | } | ||
. | .slider { | ||
position: relative; | |||
width: 100%; | |||
height: 469px; | |||
overflow: hidden; | |||
} | } | ||
. | .slider img { | ||
opacity: 0; | |||
width: 100%; | |||
height: 100%; | |||
object-fit: cover; | |||
object-position: center; | |||
transition: opacity 700ms ease-in-out; | |||
position: absolute; | |||
} | } | ||
.arrow { | |||
cursor: pointer; | |||
position: absolute; | position: absolute; | ||
top: 50%; | top: 50%; | ||
width: auto; | |||
padding: 16px; | |||
border: none; | margin-top: -22px; | ||
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); | |||
} | } | ||
.dots { | |||
width: max-content; | |||
text-align: center; | |||
position: absolute; | |||
left: 0; | left: 0; | ||
right: 0; | right: 0; | ||
bottom: 43px; | |||
margin: auto; | |||
} | } | ||
. | .dot { | ||
height: 12px; | |||
width: 94px; | |||
margin: 0 22px; | |||
background-color: #D9D9D9; | |||
display: inline-block; | display: inline-block; | ||
cursor: pointer; | cursor: pointer; | ||
transition: background-color 0.6s ease; | |||
} | |||
.dot.active { | |||
background-color: #717171; | |||
} | } | ||
}} | }} | ||
2024年8月18日 (日) 05:29的版本