jQuery如何实现的网站banner图片无缝轮播效果-创新互联

这篇文章给大家分享的是有关jQuery如何实现的网站banner图片无缝轮播效果的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

为郏县等地区用户提供了全套网页设计制作服务,及郏县网站建设行业解决方案。主营业务为网站制作、成都网站制作、郏县网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

本文实例讲述了jQuery实现的网站banner图片无缝轮播效果。分享给大家供大家参考,具体如下:






图片轮播




  html,body{
    padding: 0;
    margin: 0;
  }
  ul,ul li{
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .box{
  }
  #banner{
    position: relative;
    height:auto;
    overflow: hidden;
  }
  #banner ul{
    position:absolute;
  }
  #banner ul li{
    float: left;
  }
  #banner ul li img{
    width: 100%;
    height: 100%;
  }
  #banner #prevBtn,#banner #nextBtn{
    height:80px;
    width:30px;
    background:rgba(0,0,0,0.5);
    position:absolute;
    top:50%;
    margin-top:-40px;
    font-size:30px;
    line-height:80px;
    text-align:center;
    text-decoration:none;
    color:white;
    opacity: 0;
    transition: opacity 0.8s ease;
  }
  #banner #prevBtn{
    left:0;
  }
  #banner #nextBtn{
    right:0;
  }
  #banner:hover #prevBtn,#banner:hover #nextBtn{
    opacity: 1;
  }
  .dot{
    height:10px;
    width:10px;
    border-radius:10px;
    background:#2196f3;
    display:inline-block;
    margin:5px;
  }
  .on{
    background: #009688;
  }



  
    
      
        
  •                    
  •         
  •                    
  •         
  •                    
  •         
  •                    
  •         
  •                    
  •            
      
              (function($,window,document,undefinen){       $.fn.bannerSwiper=function(option){         this.default={           boxWrap:null,//必填           nextBtn:false,//是否往下启动按钮           prevBtn:false,//是否往上启动按钮           autoPlay:false,//是否启动自动播放           times:3000,//自动轮播的时间间隔,           speed:600,//点击按钮是切换的速度           circle:false,//是否启动小圆点           circleAlign:"center",//小圆点的对其方式           circleClick:false//小圆点是否可以点击         }         var self=this;         this.time=null;         this.options=$.extend({},this.default,option);         self.flag=true;         // 插件入口         this.init=function(){           this.bulid();         }         this.bulid=function(){           var self=this;           var wrap=self.options.boxWrap;           self.num=1;           self.nowTime=+new Date();           self.width=$(window).width();           var firstImg=$(wrap).find('li').first();           var lastImg=$(wrap).find('li').last();           $(wrap).append(firstImg.clone());           $(wrap).prepend(lastImg.clone());           self.length=$(wrap).find('li').length;           $(wrap).width(self.width*self.length);           $(wrap).find('li').width(self.width)           $(wrap).parent().height(480);           $(wrap).parent().width(self.width);           $(wrap).css({'left':-self.width*self.num})           // 是否启动自动轮播           if(self.options.autoPlay){             self.plays();           }           // 是否启动按钮           if(self.options.nextBtn){             self.NextBtn();           }           // 是否启动按钮           if(self.options.prevBtn){             self.prevBtn();           }           // 是否启动小圆点           if(self.options.circle){             self.circle()           }           if(self.options.circleClick){             self.clickCircle();           }         }         // // 鼠标移入时         self.on('mouseenter',function(){           self.stops();         })         // 鼠标移出时         self.on('mouseleave',function(){           self.plays(1);         })         // 开始计时器,自动轮播         this.plays=function(){           var self=this;           // self.stops();           console.log('play')           this.time=setInterval(function(){             self.go(-self.width)           },self.options.times);         }         // 停止计时器         this.stops=function(){           console.log('stop');           clearInterval(self.time)         }         // 手动创建按钮元素         this.prevBtn=function(){           var self=this;           var ele=$("<");           self.append(ele);           $('#prevBtn').bind("click",function(){             self.go(self.width);           })         }         // 手动创建按钮元素         this.NextBtn=function(){           var self=this;           var ele=$(">");           self.append(ele)           $('#nextBtn').bind("click",function(){             self.go(-self.width);           })         }         // 手动创建小圆点         this.circle=function(){           var self=this;           var ele=$('
    ');           for(var i=0;i').appendTo(ele)           }           ele.css({             "position":"absolute",             'bottom':'0',             'right':'0',             'left':'0',             'height':'20px',             "padding":"0 10px",             'text-align':self.options.circleAlign           });           self.append(ele);           self.playCircle(this.num-1);         }         //小圆点指定当前项         this.playCircle=function(num){           $('#circle-wrap').find('.dot').eq(num).addClass('on').siblings().removeClass('on');         }         // 点击小圆点         this.clickCircle=function(){           var self=this;           $('#circle-wrap').find('.dot').on('click',function(){             self.num=$(this).index()+1;             self.circlePlay()           })         }         // 点击小圆点,图片切换         this.circlePlay=function(){           self.flag=true;           if(self.flag){             self.flag=false;             $(self.options.boxWrap).stop().animate({               'left':-self.num*self.width             },self.options.speed,function(){               self.flag=true;             });           }           self.playCircle(this.num-1);         }         // 点击按钮,进行轮播,以及自动轮播         this.go=function(offset){           var self=this;           if(self.flag){             self.flag=false;              if(offset<0){                self.num++;                if(self.num>self.length-2){                  self.num=1;                }              }              if(offset>0){                self.num--;                if(self.num<=0){                 self.num=self.length-2                }              }              if(Math.ceil($(self.options.boxWrap).position().left)<-(self.length-2)*self.width){               $(self.options.boxWrap).css({                 'left':-self.width               });             }             if(Math.ceil($(self.options.boxWrap).position().left)>-self.length){               $(self.options.boxWrap).css({                 'left':-self.width*(self.length-2)               })             }             self.playCircle(this.num-1);             $(self.options.boxWrap).stop().animate({               'left':$(self.options.boxWrap).position().left+offset             },self.options.speed,function(){               self.flag=true;             });           }         }         this.init();       }     })(jQuery,window,document)     $('#banner').bannerSwiper({       boxWrap:"#banner-wrap",       nextBtn:true,       prevBtn:true,       autoPlay:true,       circle:true,       circleClick:true     })   

    运行效果:

    jQuery如何实现的网站banner图片无缝轮播效果

    jquery是什么

    jquery是一个简洁而快速的JavaScript库,它具有独特的链式语法和短小清晰的多功能接口、高效灵活的css选择器,并且可对CSS选择器进行扩展、拥有便捷的插件扩展机制和丰富的插件,是继Prototype之后又一个优秀的JavaScript代码库,能够用于简化事件处理、HTML文档遍历、Ajax交互和动画,以便快速开发网站。

    感谢各位的阅读!关于“jQuery如何实现的网站banner图片无缝轮播效果”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

    另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


    本文题目:jQuery如何实现的网站banner图片无缝轮播效果-创新互联
    标题来源:http://myzitong.com/article/cogjeg.html

    其他资讯