用jq实现无限轮播
来源:互联网 发布:刷棒棒糖辅助软件 编辑:程序博客网 时间:2024/06/03 16:54
<!DOCTYPE html><html lang="en"> <head> <meta charset="utf-8"> <style> *{margin: 0;padding: 0} .wrapper{position: relative;overflow: hidden;} .wrapper-content{position: absolute;left: 0;z-index: 1;} .wrapper-content_img{border: none;outline:none;float: left} .wrapper-buttons{position: absolute;width: 100px;height: 20px;text-align: center;bottom: 3px;z-index: 2;} .wrapper-button{float: left;width: 20px;height: 20px;border-radius: 10px;background: gray;margin: 0 2.5px;cursor: pointer;} .wrapper-arrow{position: absolute;width: 40px;height:40px;cursor: pointer;background-color: RGBA(0,0,0,.3); color: #fff;display: none;top:50%;line-height: 40px;font-size: 36px;text-align: center;z-index: 2;} .wrapper:hover .wrapper-arrow{display: block;background-color: rgba(0,0,0,.7);} .wrapper-prev{left:10px;} .wrapper-next{right:10px;} .wrapper_on{background-color: yellow} </style> </head> <body> <div class="wrapper"> <div class="wrapper-content"> <img class="wrapper-content_img" alt="4" src="img/4.jpg"/> <img class="wrapper-content_img" alt="1" src="img/1.jpg"/> <img class="wrapper-content_img" alt="2" src="img/2.jpg"/> <img class="wrapper-content_img" alt="3" src="img/3.jpg" /> <img class="wrapper-content_img" alt="4" src="img/4.jpg" /> <img class="wrapper-content_img" alt="1" src="img/1.jpg" /> </div> <div class="wrapper-buttons"> <span class="wrapper-button wrapper_on" index="1" ></span> <span class="wrapper-button" index="2"></span> <span class="wrapper-button" index="3"></span> <span class="wrapper-button" index="4"></span> </div> <a href="javascript:;" class="wrapper-arrow wrapper-prev"><</a> <a href="javascript:;" class="wrapper-arrow wrapper-next">></a> </div> <script type="text/javascript" src="js/jquery.js"></script> <script type="text/javascript"> $(function(){ function Slide(){ this.data={ img_width:300, img_height:300, btn_width:40, btn_height:40, num:4, delay:300 }; var self=this this.index=1; this.timer=null; this.wrapper=$('.wrapper'); this.wrapperContent=$('.wrapper-content'); this.wrapperContentImg=$('.wrapper-content_img'); this.wrapperButton=$('.wrapper-button'); this.wrapperButtons=$('.wrapper-buttons') this.wrapperPrev=$('.wrapper-prev'); this.wrapperNext=$('.wrapper-next'); this.setCss() this.wrapper.hover(function(){ self.stop() }, function(){ self.play() }) this.play() this.wrapperPrev.bind('click',function(){ self.prev() }) this.wrapperNext.bind('click',function(){ self.next() }) this.wrapperButton.each(function(){ var _this=self $(this).bind('click',function(){ if (_this.wrapperContent.is(':animated') || $(this).attr('class')=='on') { return; } var offset=($(this).attr('index')-_this.index)*_this.data.img_width; _this.index=$(this).attr('index') _this.animate(offset) _this.showButton() }) }) } Slide.prototype={ setCss:function(){ var self=this; this.wrapper.css({ width:self.data.img_width, height:self.data.img_height, }) this.wrapperContent.css({ left:-self.data.img_width, width:self.data.img_width*(self.data.num+2), height:self.data.img_height, }) this.wrapperPrev.css({ marginTop:-parseInt(self.data.btn_height/2) }) this.wrapperNext.css({ marginTop:-parseInt(self.data.btn_height/2) }) this.wrapperContentImg.css({ width:self.data.img_width, height:self.data.img_height }) this.wrapperButtons.css({ left:(self.data.img_width-100)/2 }) }, next:function(){ if(this.wrapperContent.is(':animated')){ return } if(this.index==this.data.num){ this.index=1 }else{ this.index+=1 } this.animate(this.data.img_width) this.showButton() }, prev:function(){ if(this.wrapperContent.is(':animated')){ return } if(this.index==1){ this.index=this.data.num }else{ this.index-=1 } this.animate(-this.data.img_width) this.showButton() }, animate:function(offset){ var self=this; var left=parseInt(this.wrapperContent.css('left'))-offset this.wrapperContent.animate({ left:left },this.data.delay,function(){ if(left<-self.data.num*self.data.img_width){ self.wrapperContent.css({left:-self.data.img_width}) } if(left>-100){ self.wrapperContent.css({left:-self.data.num*self.data.img_width}) } }) }, showButton:function(){ this.wrapperButton.eq(this.index-1).addClass('wrapper_on').siblings().removeClass('wrapper_on') }, play:function(){ var self=this this.timer=setInterval(function(){ self.wrapperNext.trigger('click') },2000) }, stop:function(){ var self=this clearInterval(self.timer) } } new Slide() }) </script> </body></html>
0 0
- 用jq实现无限轮播
- JQ无限轮播
- jq实现轮播
- JQ实现轮播
- jq 实现无缝轮播
- collectionview实现无限轮播
- 无限轮播 实现原理
- 无限轮播的实现
- 无限轮播的实现
- ViewPager实现无限轮播
- ViewPager无限轮播实现
- banner实现无限轮播
- Banner实现无限轮播
- Banner实现无限轮播
- banner实现无限轮播
- 实现利用jq图片点击轮播
- 如何用jq实现图片轮播
- 淡入淡出背景轮播 jq实现
- Thymeleaf中用HTML5语法设置标签和属性
- Jetty Continuation机制
- 第一篇test
- LeetCode : Fizz Buzz
- 试题_(带分数)03
- 用jq实现无限轮播
- CCF CSP 压缩编码
- mysqldump: Couldn't execute 'SAVEPOINT sp'
- FFmpeg常用推流命令
- [LeetCode]---word-break
- 棋牌游戏服务器架构设计
- 这8种武器点亮程序员的个人品牌
- 趣写算法系列之--匈牙利算法
- Servlet 3之异步处理特性