本文为大家分享了js图片轮播插件的具体代码,供大家参考,具体内容如下
我封装的这个轮播插件只需要获取到图片和按钮就可以啦。
css 样式
.body{ width: 700px; margin: 100px auto; position: relative; height: 300px; overflow: hidden; } .body img{ width: 700px; position: absolute; display: none; } .body ul{ position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%); } .body li{ list-style: none; float: left; width: 15px; height: 15px; border-radius: 50px; background: none; border: 2px solid #fff; margin-right: 10px; cursor: pointer; } .active{ background-color: #fff !important; } .body a{ text-decoration: none; position: absolute; display: block; top: 50%; transform: translateY(-50%); height: 50px; width: 30px; background-size: 100% 60%; background-color: rgba(0,0,0,0.3); } .left{ left: 0; background: url('../img/left.png') no-repeat center center; } .right{ right: 0; background: url('../img/right.png') no-repeat center center; }
页面结构 html 代码
<body> <div class="body"> <img src="/UploadFiles/2021-04-02/1.jpg">js部分,插件调用
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery-1.8.0.min.js">封装的插件
(function($){ function slider(options){ this.opts=$.extend({},slider.defaluts,options); this._imgSlider(); } //设置默认值 slider.defaluts={ imgElement:null, liElement:null, leftBtn:null, rightBtn:null, time:2000 } slider.prototype._imgSlider=function(){ var opts=this.opts, index=0, len=opts.imgElement.length, timeInter=null; if(opts.imgElement=='') return; opts.imgElement.eq(0).show(); showTime(); //当鼠标经过 轮播停止,移开继续 opts.imgElement.hover(function() { clearInterval(timeInter); }, function() { showTime(); }); //点击li 显示对应的图片 opts.liElement.click(function(){ var id=$(this).index(); show(id); }); //向左向右 opts.leftBtn.click(function(){ clearInterval(timeInter); --index; index=Math.max(0,index); show(index); showTime(); }); opts.rightBtn.click(function(){ clearInterval(timeInter); ++index; index=Math.min(len-1,index); show(index); showTime(); }); function showTime(){ timeInter=setInterval(function(){ index++; if(index>len){ index=0; } show(index); },opts.time); } function show(index){ opts.imgElement.eq(index).fadeIn(1000).siblings('img').fadeOut(1000); opts.liElement.eq(index).addClass('active').siblings('li').removeClass('active'); } } $.extend({ slider:function(options){ new slider(options); } }) })(jQuery)效果图
精彩专题分享:jQuery图片轮播 JavaScript图片轮播 Bootstrap图片轮播
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 《汽车发烧音乐精选CD18》[FLAC+CUE][7.1G]
- 郑希怡.2004-Perfect.Date【英皇娱乐】【FLAC分轨】
- 群星.1994-宝丽金超级孖宝2CD【宝丽金】【WAV+CUE】
- 林忆莲.2019-0(2023精装版)【环球】【WAV+CUE】
- Supper.Moment.2016-The.Moment【寰亚】【FLAC分轨】
- 范莉丝.1979-送郎一朵牵牛花(LP版)【大联机构】【WAV+CUE】
- 刘宇.2024-宇宙诗人【哔哟哔哟文化】【FLAC分轨】
- 《全景声白噪音》沉浸式大自然助眠 带你听自然的声音[mp3]
- 纯音入心系列纯音乐《古筝精选 十指弹一赏心曲一心奏出世人心》1CD[MP3][582MB]
- 纯音入心系列纯音乐《古筝与现代音乐的交织》1CD[MP3][96MB]
- 王俪婷.2011-ROMANCE【华研国际】【WAV+CUE】
- 狮子合唱团.2016-LION(引进版)【华纳】【WAV+CUE】
- 范文芳.1996-FNNTASY【HYPE】【WAV+CUE】
- 纯音入心系列纯音乐《韵味古筝曲》1CD[MP3][146.2MB]
- 纯音入心系列纯音乐《古筝系列-传统乐曲》1CD[MP3][974.7MB]