DDR爱好者之家 Design By 杰米
原生JS仿小米轮播图(最新版易懂),供大家参考,具体内容如下
本次内容主要可实现的效果:
- 自动轮播
- 可点击上一张 下一张进行图片的切换
- 点击右下方小圆点进行图片切换
代码部分:
H5:
<div class="wrap"> <ul class="list"> <li class="item active"><img src="/UploadFiles/2021-04-02/001.jpg">CSS部分:
<style> .wrap { width: 800px; height: 400px; position: relative; } .list { width: 800px; height: 400px; list-style: none; position: relative; padding-left: 0px; } .item { position: absolute; width: 100%; height: 100%; color: white; font-size: 50px; opacity: 0.6; transform: all .8s; } .item img{ width: 800px; height: 400px; } .btn { width: 50px; height: 100px; position: absolute; top: 150px; z-index: 100; } #goPre { left: 0px; } #goNext { right: 0px; } .item.active { opacity: 1; z-index: 10; } .pointList{ padding-left: 0; list-style: none; position: absolute; right: 20px; bottom: 20px; z-index: 1000; } .point{ width: 10px; height: 10px; background-color: rgba(0,0,0,0.4); border-radius: 50%; float: left; margin-right: 16px; border-style: solid; border-width: 2px; border-color: rgba(255,255,255, 0.6); cursor: pointer; } .point.active{ background-color: rgba(255,255,255,0.4); } </style>JS部分
<script> //获取节点 var items = document.getElementsByClassName('item')//图片 var goPreBtn = document.getElementById('goPre'); var goNextBtn = document.getElementById('goNext'); //获取点 var points=document.getElementsByClassName('point'); var time=0;//定时器图片跳转参数 var index = 0; //表示第几张图片在展示 //可以展示第几个点 var clearActive=function(){ for(var i=0;i<items.length;i++){ items[i].className='item'; points[i].className='point'; } } var goIndex=function(){ clearActive(); items[index].className='item active'; points[index].className='point active'; } var goNext=function(){ if(index<4){ index++; }else{ index=0; } goIndex(); } var goPre=function(){ if(index==0){ index=4; }else{ index--; } goIndex(); } //点击下一张切换图片 goNextBtn.addEventListener('click' ,function(){ goNext(); time=0; }) //点击上一张进行切换图片 goPreBtn.addEventListener('click' ,function(){ goPre(); time=0; }) for(var i=0;i<points.length;i++){ points[i].addEventListener('click',function(){ var pointIndex=this.getAttribute('data-index'); index=pointIndex; goIndex(); time=0; }) } //自动轮播定时器 setInterval(function(){ time++; if(time==20){ goNext(); time=0; } },100) </script>以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年09月20日
2024年09月20日
- 王菲.2006《菲常好听》引进版[低速原抓WAV+CUE]
- 《三日危情独家的记忆》女角色介绍
- 《天国拯救》拉泰比武大会攻略
- 任天堂推出《马里奥惊奇》NS捆绑包 10月24日发售
- 《孤岛惊魂》能否逆转育碧颓势?曝系列新作正招兵买马
- 天命人呼叫战术轰炸!玩家自制《黑神话:悟空》轰炸机Mod
- 群星.1992-滚石九大天王·十二出好戏【滚石】【WAV+CUE】
- 群星.1994-新滚石九大天王之年度大丫滚石】【WAV+CUE】
- 坣娜.1998-别恋【非常喜】【WAV+CUE】
- 《草原经典 最炫草原风 2CD》[WAV/分轨][980MB]
- 《不烧不选 经典国语极品珍藏》[WAV/分轨][500MB]
- 《绝对主打 流行原创金曲 2CD》[WAV分轨][1.1GB]
- 《赛博朋克2077》更新上线:支持AMD FSR3
- 《塞尔达传说:智慧的再现》提前半个月偷跑,引发玩家担忧
- 战锤40K星际战士2全职业介绍|全职业技能效果一览