色婷婷狠狠18禁久久YY,CHINESE性内射高清国产,国产女人18毛片水真多1,国产AV在线观看

css帶圓點輪播圖代碼

錢斌斌2年前9瀏覽0評論

現在大多數網站都會采用輪播圖來展示頁面上的圖片,那么如何使用CSS來制作帶圓點輪播圖呢?下面我們就來一起學習一下:

<html>
<head>
<title>CSS帶圓點輪播圖</title>
<style>
.slider {
width: 800px;
height: 500px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
.slider .slide {
width: 800px;
height: 500px;
position: absolute;
top: 0;
display: none;
opacity: 0;
transition: opacity .5s;
}
.slider .slide.active {
display: block;
opacity: 1;
}
.slider .slider-dots {
width: 100%;
position: absolute;
bottom: 20px;
text-align: center;
}
.slider .slider-dots span {
display: inline-block;
width: 10px;
height: 10px;
margin: 0 5px;
background-color: #ccc;
border-radius: 50%;
cursor: pointer;
}
.slider .slider-dots span.active {
background-color: #666;
}
</style>
</head>
<body>
<div class="slider">
<div class="slide active"><img src="images/slide-1.jpg" alt=""></div>
<div class="slide"><img src="images/slide-2.jpg" alt=""></div>
<div class="slide"><img src="images/slide-3.jpg" alt=""></div>
<div class="slider-dots">
<span class="active"></span>
<span></span>
<span></span>
</div>
</div>
<script>
var slides = document.querySelectorAll('.slide');
var dots = document.querySelectorAll('.slider-dots span');
var currentSlide = 0;
function showSlide(n) {
if (n< 0) {
currentSlide = slides.length - 1;
} else if (n >= slides.length) {
currentSlide = 0;
} else {
currentSlide = n;
}
for (var i = 0; i< slides.length; i++) {
slides[i].classList.remove('active');
dots[i].classList.remove('active');
}
slides[currentSlide].classList.add('active');
dots[currentSlide].classList.add('active');
}
function nextSlide() {
showSlide(currentSlide + 1);
}
setInterval(nextSlide, 3000);
for (var i = 0; i< dots.length; i++) {
(function(i) {
dots[i].addEventListener('click', function() {
showSlide(i);
});
})(i);
}
</script>
</body>
</html>

以上代碼就是我們完整的帶圓點輪播圖的CSS代碼,其中主要的就是針對輪播圖和圓點的樣式設計,以及使用JavaScript來實現輪播圖的自動播放和點擊圓點進行切換圖片的功能。通過這些代碼,我們可以制作出一個簡單卻實用的輪播圖,給網站頁面添加更加醒目的效果。