jQuery實(shí)現(xiàn)的網(wǎng)站banner圖片無(wú)縫輪播效果完整實(shí)例
本文實(shí)例講述了jQuery實(shí)現(xiàn)的網(wǎng)站banner圖片無(wú)縫輪播效果。分享給大家供大家參考,具體如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>圖片輪播</title>
<meta name="description" content="">
<meta name="keywords" content="">
<link href="" rel=" rel="external nofollow" stylesheet">
<style type="text/css">
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;
}
</style>
</head>
<body>
<div class="box">
<div id="banner">
<ul id="banner-wrap">
<li>
<img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img1.jpg">
</li>
<li>
<img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img2.jpg">
</li>
<li>
<img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img3.jpg">
</li>
<li>
<img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img4.jpg">
</li>
<li>
<img src="http://www.zxhuan.com/wp-content/uploads/2016/02/img5.jpg">
</li>
</ul>
</div>
</div>
<script type="text/javascript" src='http://libs.baidu.com/jquery/2.0.0/jquery.js'></script>
<script type="text/javascript">
(function($,window,document,undefinen){
$.fn.bannerSwiper=function(option){
this.default={
boxWrap:null,//必填
nextBtn:false,//是否往下啟動(dòng)按鈕
prevBtn:false,//是否往上啟動(dòng)按鈕
autoPlay:false,//是否啟動(dòng)自動(dòng)播放
times:3000,//自動(dòng)輪播的時(shí)間間隔,
speed:600,//點(diǎn)擊按鈕是切換的速度
circle:false,//是否啟動(dòng)小圓點(diǎn)
circleAlign:"center",//小圓點(diǎn)的對(duì)其方式
circleClick:false//小圓點(diǎn)是否可以點(diǎn)擊
}
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})
// 是否啟動(dòng)自動(dòng)輪播
if(self.options.autoPlay){
self.plays();
}
// 是否啟動(dòng)按鈕
if(self.options.nextBtn){
self.NextBtn();
}
// 是否啟動(dòng)按鈕
if(self.options.prevBtn){
self.prevBtn();
}
// 是否啟動(dòng)小圓點(diǎn)
if(self.options.circle){
self.circle()
}
if(self.options.circleClick){
self.clickCircle();
}
}
// // 鼠標(biāo)移入時(shí)
self.on('mouseenter',function(){
self.stops();
})
// 鼠標(biāo)移出時(shí)
self.on('mouseleave',function(){
self.plays(1);
})
// 開始計(jì)時(shí)器,自動(dòng)輪播
this.plays=function(){
var self=this;
// self.stops();
console.log('play')
this.time=setInterval(function(){
self.go(-self.width)
},self.options.times);
}
// 停止計(jì)時(shí)器
this.stops=function(){
console.log('stop');
clearInterval(self.time)
}
// 手動(dòng)創(chuàng)建按鈕元素
this.prevBtn=function(){
var self=this;
var ele=$("<a href='javascript:;' id='prevBtn'><</a>");
self.append(ele);
$('#prevBtn').bind("click",function(){
self.go(self.width);
})
}
// 手動(dòng)創(chuàng)建按鈕元素
this.NextBtn=function(){
var self=this;
var ele=$("<a href='javascript:;' id='nextBtn'>></a>");
self.append(ele)
$('#nextBtn').bind("click",function(){
self.go(-self.width);
})
}
// 手動(dòng)創(chuàng)建小圓點(diǎn)
this.circle=function(){
var self=this;
var ele=$('<div id="circle-wrap"></div>');
for(var i=0;i<self.length-2;i++){
$('<a class="dot" href="javascript:;" rel="external nofollow" ></a>').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);
}
//小圓點(diǎn)指定當(dāng)前項(xiàng)
this.playCircle=function(num){
$('#circle-wrap').find('.dot').eq(num).addClass('on').siblings().removeClass('on');
}
// 點(diǎn)擊小圓點(diǎn)
this.clickCircle=function(){
var self=this;
$('#circle-wrap').find('.dot').on('click',function(){
self.num=$(this).index()+1;
self.circlePlay()
})
}
// 點(diǎn)擊小圓點(diǎn),圖片切換
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);
}
// 點(diǎn)擊按鈕,進(jìn)行輪播,以及自動(dòng)輪播
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
})
</script>
</body>
</html>
運(yùn)行效果:

感興趣的朋友可以使用在線HTML/CSS/JavaScript代碼運(yùn)行工具:http://tools.jb51.net/code/HtmlJsRun測(cè)試上述代碼運(yùn)行效果。
更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery圖片操作技巧大全》、《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》
希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。
- jQuery.parseJSON()函數(shù)詳解
- jQuery each和js forEach用法比較
- 詳解JavaScript原生封裝ajax請(qǐng)求和Jquery中的ajax請(qǐng)求
- Jquery實(shí)現(xiàn)無(wú)縫向上循環(huán)滾動(dòng)列表的特效
- jquery無(wú)縫圖片輪播組件封裝
- 在Vue項(xiàng)目中引入JQuery-ui插件的講解
- 在vue項(xiàng)目中使用Jquery-contextmenu插件的步驟講解
- Node.js Event Loop各階段講解
- 零基礎(chǔ)之Node.js搭建API服務(wù)器的詳解
- Jquery的autocomplete插件用法及參數(shù)講解
相關(guān)文章
JQuery將文本轉(zhuǎn)化成JSON對(duì)象需要注意的問(wèn)題
在JQuery的許多方法中,很多方法的參數(shù)可以傳入一個(gè)JSON對(duì)象,比如Ajax方法的第二個(gè)參數(shù)。怎么將文本轉(zhuǎn)化成JSON對(duì)象,需要注意以下問(wèn)題2011-05-05
基于jQuery架構(gòu)javascript基礎(chǔ)體系
jQuery畢竟還只是一個(gè)基礎(chǔ)的最底層的工具集,封裝元素選擇器,事件等等,基本上能滿足一般的需求,但要從整體的WEB的周度來(lái)看,為了提高javascript開發(fā)的效率與可重用性,就需要有一個(gè)整體的布局2011-01-01
JQuery實(shí)現(xiàn)網(wǎng)頁(yè)右側(cè)隨動(dòng)廣告特效
本文給大家分享的是2則使用jquery實(shí)現(xiàn)網(wǎng)頁(yè)右側(cè)隨動(dòng)廣告特效的代碼,非常的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。2016-01-01
jQuery web 組件 后臺(tái)日歷價(jià)格、庫(kù)存設(shè)置的代碼
這篇文章主要介紹了jQuery web 組件 后臺(tái)日歷價(jià)格、庫(kù)存設(shè)置的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
jquery改變disabled的boolean狀態(tài)的三種方法
改變disabled的boolean狀態(tài),下面為大家介紹三種比較不錯(cuò)的方法,大家可以參考下2013-12-12
jquery表單驗(yàn)證實(shí)例仿Toast提示效果
這篇文章主要介紹了jquery驗(yàn)證表單仿Toast提示效果,實(shí)現(xiàn)代碼簡(jiǎn)單易懂,非常不錯(cuò),需要的朋友可以參考下2017-03-03

