本文实例为大家分享了js+html+css实现手动轮播和自动轮播的具体代码,供大家参考,具体内容如下
原理:设置图片层的总长=单张图片长度*张数;在轮播层中利用overflow只留出一张图片的显示; 通过图片层的left来显示轮播的每一张图,第一张为0,为了后面的图片显示,left的值左移为负数。
原理图
代码:
轮播图 *{ margin: 0; padding: 0; } ul{ list-style: none; } a{ text-decoration: none; } #container{ position: relative; width: 500px; height: 260px; margin: 20px auto; overflow: hidden; } #container .parent{ position: absolute; width: 2500px; height: 260px; } #container .parent li{ float: left; width: 500px; height: 100%; } #container .parent li img{ width: 100%; height: 100%; } #container .btnLeft, #container .btnRight{ width: 30px; height: 30px; background-color: #9E9E9E; border-radius: 20%; opacity: 80%; position: absolute; top: 0; bottom: 0; margin: auto; font-size: 20px; color: #f40; text-align: center; line-height: 30px; } #container .btnLeft{ left: 10px; } #container .btnRight{ right: 10px; } #container .btnLeft:hover, #container .btnRight:hover{ opacity: 90%; cursor: pointer; } #container .modal{ width: 100%; height: 40px; background: rgba(0,0,0,.3); position: absolute; left: 0; bottom: 0; line-height: 40px; padding: 0 40px; box-sizing: border-box; } #container .modal .title{ float: left; color: #fff; font-size: 12px; } #container .modal .dots{ float: right; position: absolute; bottom: 10px; left: 340px; } #container .modal .dots li{ width: 15px; height: 15px; border-radius: 50%; float: left; margin: 0 5px; cursor: pointer; } .clearfix::after{ content: ""; display: block; clear: both; } .on{ background-color: red; } .off{ background-color: gray; } < > 轮播图
效果:按钮左右滑动图片,图片上的小圆点也可以选择图片。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。



