当前位置:首页 » 《随便一记》 » 正文

用jQuery实现轮播图——超简单(代码解释)

0 人参与  2022年12月10日 09:45  分类 : 《随便一记》  评论

点击全文阅读


先看效果
鼠标悬浮时停止轮播,离开时自动轮播,点下一张小圆点会随着动

效果图

直接上代码

<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><style>.wrapper {width: 600px;height: 350px;border: 1px solid red;position: relative;}/* 5张图片叠加到一块 */.wrapper img {width: 100%;height: 100%;position: absolute;left: 0;top: 0;display: none;}.wrapper img:nth-of-type(1) {display: block;}/* 小圆点 */.btn {width: 150px;display: flex;justify-content: space-around;position: absolute;left: 225px;bottom: 10px;z-index: 100}.btn span {display: block;width: 15px;height: 15px;border: 3px solid white;border-radius: 50%;}/* 左右箭头 */.wrapper a {text-decoration: none;font-size: 50px;color: red;position: absolute;top: 35%;}.wrapper a:nth-of-type(1) {left: 10px;}.wrapper a:nth-of-type(2) {right: 10px;}.active {background-color: red;}</style></head><body><div class="wrapper"><div class="contain"><img src="./imgs/1.png" alt=""><img src="./imgs/2.png" alt=""><img src="./imgs/3.png" alt=""><img src="./imgs/4.png" alt=""><img src="./imgs/5.png" alt=""></div><div class="btn"><span class="active"></span><span></span><span></span><span></span><span></span></div><a href="javascript:void(0);">&lt;</a><a href="javascript:void(0);">&gt;</a></div><script src="js/jquery-3.6.0.js"></script><script>var index=0;// 点击上一张$("a:first").click(function(){prev_pic();})// 点击下一张$("a:last").click(function(){next_pic();})// 悬浮停止$(".wrapper").mouseover(function(){clearInterval(id);});$(".wrapper").mouseout(function(){autoplay();})// 下一张function next_pic(){index++;if(index>4){index=0;}addStyle();}// 上一张function prev_pic(){index--;if(index<0){index=4;}addStyle();}// 控制图片显示隐藏,小圆点背景色function addStyle(){$("img").eq(index).fadeIn();$("img").eq(index).siblings().fadeOut();$("span").eq(index).addClass("active");$("span").eq(index).siblings().removeClass("active");}// 自动轮播var id;autoplay();function autoplay(){id=setInterval(function(){next_pic();},1000)}</script></body></html>

这里只要把图片地址更换一下 ,引用jquery文件就可以了


点击全文阅读


本文链接:http://m.zhangshiyu.com/post/49553.html

<< 上一篇 下一篇 >>

  • 评论(0)
  • 赞助本站

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

  • (心声暴露,兽夫们夜夜熬红眼)心声暴露,兽夫们夜夜熬红眼小说(苏沫)无套路无弹窗全部章节列表
  • 许清梨贺南舟后续(许清梨贺南舟)(他在回忆尽头)完整章节列表_笔趣阁
  • 高分_李象小说(大唐之最强皇太孙)(李象)全本完整阅读
  • 他在回忆尽头::结局+番外评价五颗星-许清梨贺南舟:结局+番外新上热文
  • 叶薇,萧逸璃纹双璧,情定此生电子书+番外篇章+(璃纹双璧,情定此生)免费版在线阅读
  • 林蔓枝,墨冽完结篇(身怀空间,我在兽世荒漠养兽夫)章节:结局+番外评价五颗星
  • 我被虐杀装进花瓶后,跪求我出山的首富悔疯了林璐璐,沈崇山,沈耀+后续+番外必读文-(我被虐杀装进花瓶后,跪求我出山的首富悔疯了)林璐璐,沈崇山,沈耀后续+番外精编之作笔趣阁
  • 季先生,您前妻算卦超灵!最新章节_白笙季云霆看点十足_小说后续在线阅读_无删减免费完结_
  • 恶雌会读心?五个兽夫追着我求宠阮阮:+后续+番外+附加(阮阮)清爽版阅读
  • 璃纹双璧,情定此生全篇完整在线阅读(叶薇,萧逸)热门章节列表
  • 静默奔溃无广告阅读_沈铮静姐陈静精心编著_小说后续在线阅读_无删减免费完结_
  • 男友装穷考验我99次,我转身继承首(谢先生,谢邸,谢夫人)全书免费_(谢先生,谢邸,谢夫人)男友装穷考验我99次,我转身继承首后续(谢先生,谢邸,谢夫人)

    关于我们 | 我要投稿 | 免责申明

    Copyright © 2020-2022 ZhangShiYu.com Rights Reserved.豫ICP备2022013469号-1