用html+css怎么写出带按钮的轮播图?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用html+css怎么写出带按钮的轮播图?相关的知识,希望对你有一定的参考价值。

三张图片轮流播放,下面有三个小原点跟着图片一起动,

参考技术A <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>css实现轮播图</title>
<style>
body
margin: 0;
background: #dfe;


ul
margin: 0;
padding: 0;
list-style: none;


.my-swiper
position: relative;
width: 800px;
height: 450px;
margin: 100px auto;
overflow: hidden;


.swiper-list
position: absolute;
top: 0;
left: 0;
width: 4000px;
height: 100%;
overflow: hidden;
animation: swiper 10s steps(1, end) infinite;
transition: left 1s linear;


.swiper-slide
width: 800px;
height: 100%;
float: left;
overflow: hidden;


.swiper-slide a
display: block;
height: 100%;


.swiper-slide img
display: block;
width: 100%;
height: 100%;
object-fit: cover;


/* 分页 */
.pagination
position: absolute;
bottom: 0;
left: 0;
right: 0;
line-height: 45px;
background: rgba(255, 255, 255, 0.3);
text-align: center;


.dot
display: inline-block;
width: 10px;
height: 10px;
margin: 0 2px;
background: #fff;
border-radius: 50%;

/* 橙色小圆点 */
.dot.active
position: absolute;
left: 356px;
top: 18px;
width: 11px;
height: 11px;
margin: 0;
background: tomato;
animation: swiper-dot 10s steps(1, end) infinite;
transition: left 1s linear;


@keyframes swiper

0%,
100%
left: 0;


20%
left: -800px;


40%
left: -1600px;


60%
left: -2400px;


80%
left: -3200px;


/* 100%
left: -3200px;
*/

@keyframes swiper-dot

0%,
100%
left: 358px;


20%
left: 376px;


40%
left: 395px;


60%
left: 413px;


80%
left: 432px;



</style>

</head>
<body>
<div>
<ul>
<li class="swiper-slide swiper-slide1">
<a href="javascript:;">
<img src="banner.jpg" alt="">
</a>
</li>
<li class="swiper-slide swiper-slide2">
<a href="javascript:;">
<img src="banner1.jpg" alt="">
</a>
</li>
<li class="swiper-slide swiper-slide3">
<a href="javascript:;">
<img src="banner2.jpg" alt="">
</a>
</li>
<li class="swiper-slide swiper-slide4">
<a href="javascript:;">
<img src="banner.jpg" alt="">
</a>
</li>
<li class="swiper-slide swiper-slide5">
<a href="javascript:;">
<img src="banner1.jpg" alt="">
</a>
</li>
</ul>
<div>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span class="dot active"></span>
</div>
</div>
</body>
</html>本回答被提问者采纳

用js函数封装一个上下滑动的轮播图,调用任意

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
.tab{
width: 500px;
height: 300px;
border: 1px solid red;
margin: 0 auto;
overflow: hidden;
position: relative;
}
*{
margin: 0;
padding: 0;
}
ul{
transition: 1s;
}
ul,ol{
list-style: none;
}
a{
text-decoration: none;
}
ul li{
width: 500px;
height: 300px;
text-align: center;
line-height: 300px;
color: white;
font-size: 100px;
}
ol .active{
background:black;
}
ul li:nth-child(1){
background: red;
}
ul li:nth-child(2){
background:yellow;
}
ul li:nth-child(3){
background:green;
}
ol{
position: absolute;
width: 100px;
height: 30px;
/*background: black;*/
bottom: 20px;
left: 50%;
margin-left: -50px;
}
ol li{
float: left;
background: #ccc;
width: 30px;
height: 30px;
border-radius: 50%;
margin-right: 3px;
font-size: 15px;
color: white;
text-align: center;
line-height: 30px;
}
</style>
</head>
<body>
<div class="tab" id="tab1">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<ol>
<li class="active">1</li>
<li>2</li>
<li>3</li>
</ol>
</div>
<div class="tab" id="tab2">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<ol>
<li class="active">1</li>
<li>2</li>
<li>3</li>
</ol>
</div>
</body>
<script>
function $s(x){
return document.querySelectorAll(x);
}
function $(x){
return document.querySelector(x);
}
function tab(id){
var btns=$s(id+" ol li");
var picbox=$(id+" ul");
var length=btns.length;
for(i=0;i<length;i++){
btns[i].index=i;
btns[i].onclick=function(){
for(i=0;i<length;i++){
btns[i].className="";
}
picbox.style.marginTop=-300*this.index+"px";
btns[this.index].className="active";
}
}
}
tab("#tab1");
tab("#tab2");
</script>
</html>

以上是关于用html+css怎么写出带按钮的轮播图?的主要内容,如果未能解决你的问题,请参考以下文章

vue中的轮播图

手机的轮播图可以用jquery来做吗

js实现左右切换轮播图思路

浅谈轮播图(原生JavaScript实现)

Vue实现带两个方向过渡效果的轮播图

原生js实现轮播图