jq左右按钮点击幻灯片
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html > < head > < meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> < script type="text/javascript" src="js/jquery-1.7.min.js"></ script > < title >左右点击幻灯片</ title > < style type="text/css"> *{margin: 0;padding: 0;} ul{ list-style: none;} .wrapper{width: 300px;height: 200px; margin:100px auto;overflow: hidden;border: 2px solid #ccc;position: relative;} .scroll{width: 205px;margin: 0 auto; overflow: hidden;} .scroll li{float: left; margin: 5px; height:160px; font-size:60px; text-align:center; line-height:100px; font-weight:800; background:#FF3F00; color:#fff; width:200px;} .prev,.next{ width: 30px;height: 30px;background: #daa520;color: #fff;cursor: pointer;position: absolute;top:80px; text-align: center;line-height: 30px;} .next{ right: 0;} </ style > </ head > < script > $(function(){ var oScroll=$('.scroll>ul'),oLi=oScroll.find('li'),oLen=oLi.length,oPrev=$('.prev'),oNext=$('.next'),oWidth=oLi.eq(0).outerWidth(true),iNow= 1,oCur=$('.count>em'),oCount=$('.count>i'),iTimer=null; oScroll.width(oWidth*oLen); oCount.html(oLen); function count(){ oCur.html(iNow); } function Prev(){ oScroll.css({marginLeft:-oWidth+'px'}).find('li:last').prependTo(oScroll); oScroll.stop(true,true).animate({marginLeft:0+'px'},600); iNow=iNow>1?iNow-1:oLen; count(iNow); } function Next(){ oScroll.stop(true,true).animate({marginLeft:-oWidth+'px'},600,function(){ oScroll.css({marginLeft:0}).find('li:first').appendTo(oScroll); }) iNow=iNow< oLen ?iNow+1:1; count(iNow); } oPrev.bind('click',Prev); oNext.bind('click',Next); iTimer=setInterval(Next,3000); $('.wrapper').hover(function(){ clearInterval(iTimer); },function(){ iTimer=setInterval(Next,3000); }) }) </script> < body > < div class="wrapper"> < span class="prev">《</ span > < span class="next">》</ span > < div class="scroll"> < ul > < li >1</ li > < li >2</ li > < li >3</ li > < li >4</ li > </ ul > </ div > < div class="count">< em >1</ em >/< i >0</ i ></ div > </ div > </ body > </ html > |
关注web前端
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步