jQuery簡單自定義圖片輪播插件及用法示例
本文實(shí)例講述了jQuery簡單自定義圖片輪播插件及用法。分享給大家供大家參考,具體如下:
經(jīng)常使用別人的插件,現(xiàn)在自己寫一個,紀(jì)念一下。
jQuery.banner.js:
/*
* banner 0.1
* 使用banner 實(shí)現(xiàn)圖片定時切換 鼠標(biāo)經(jīng)過停止動畫
* 鼠標(biāo)離開,繼續(xù)動畫
*/
;(function($){
$.fn.banner =function(options){
//各種屬性和參數(shù)
var defaults ={
picWidth:"1000",
picHeight:"300",
speed:"1500"
};
var totalW = 0; //保存總的動畫寬度
var timer = null; //保存定時器
var current = 0; //保存當(dāng)前動畫到第N張圖,下次從這里開始
var totalNum = 0; //保存總的圖數(shù)
var Dsqtime = 0; //定義定時器時間 【外傳參數(shù)】
var Dhtime = 0; //定義動畫時間
var count = 0 ;
//合并多個對象為一個,即有新參數(shù) 用新的,否則用默認(rèn)的
var options = $.extend(defaults, options);
this.each(function(){
//實(shí)現(xiàn)代碼
var __this = $(this);
Dsqtime = options.speed;
Dhtime = Dsqtime/3;
//初始化
init(__this);
//調(diào)用動畫
show(__this, options.picWidth,current);
//鼠標(biāo)經(jīng)過時事件
__this.find('ul li').bind('mouseover',function(){
window.clearInterval(timer); //清除定時器
});
__this.find('ul li').bind('mouseout',function(){
show(__this, options.picWidth,current);
//接著上一次動畫輪播
});
});
//初始化 設(shè)定父容器寬度
function init(obj){
obj.find('ul li').each(function(){
totalW += $(this).width();
totalNum++;
});
obj.find('ul').width(totalW);
}
//開始動畫顯示
function show(obj, width, current){
timer = setInterval(function(){
obj.find('ul').animate({'margin-left':'-'+count*width+'px'},
Dhtime);
current = count;
count++;
if(count == totalNum){
count =0;
}
}, Dsqtime);
}
};
})(jQuery);
html代碼:
<!doctype html>
<html>
<head>
<meta charset="utf8"/>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/jquery.banner.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.wrap').banner({
picWidth:"1000",
picHeight:"300",
speed:"6000"
});
});
</script>
<style type="text/css">
*{margin:0;padding:0;}
.wrap{width:1000px; height:300px; overflow:hidden; margin:0 auto;}
.wrap ul li{float:left; list-style:none;}
.wrap ul li img{width:1000px;height:300px;}
.clear{clear: both;}
</style>
</head>
<body>
<div>
<div class="wrap">
<ul>
<li><a href="#"><img src="./images/1.jpg"/></a></li>
<li><a href="#"><img src="./images/2.jpg"/></a></li>
<li><a href="#"><img src="./images/3.jpg"/></a></li>
<li><a href="#"><img src="./images/4.jpg"/></a></li>
<li><a href="#"><img src="./images/5.jpg"/></a></li>
</ul>
<div class="clear"></div>
</div>
</div>
</body>
</html>
效果圖:

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery切換特效與技巧總結(jié)》、《jQuery遍歷算法與技巧總結(jié)》、《jQuery常見經(jīng)典特效匯總》、《jQuery動畫與特效用法總結(jié)》及《jquery選擇器用法總結(jié)》
希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。
- 原生js和jquery實(shí)現(xiàn)圖片輪播淡入淡出效果
- 基于jQuery實(shí)現(xiàn)淡入淡出效果輪播圖
- 原生js和jQuery實(shí)現(xiàn)淡入淡出輪播效果
- jQuery實(shí)現(xiàn)圖片簡單輪播功能示例
- jQuery實(shí)現(xiàn)的簡單圖片輪播效果完整示例
- 使用JQuery實(shí)現(xiàn)圖片輪播效果的實(shí)例(推薦)
- 純javaScript、jQuery實(shí)現(xiàn)個性化圖片輪播【推薦】
- jQuery實(shí)現(xiàn)的圖片輪播效果完整示例
- jQuery的圖片輪播插件PgwSlideshow使用詳解
- jQuery實(shí)現(xiàn)圖片輪播效果代碼(基于jquery.pack.js插件)
- jQuery實(shí)現(xiàn)的淡入淡出圖片輪播效果示例
相關(guān)文章
jQuery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊彈出漸變層的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊彈出漸變層的方法,jQuery是當(dāng)下最具人氣的JavaScript庫,需要的朋友可以參考下2015-07-07
jQuery實(shí)現(xiàn)點(diǎn)擊水紋波動動畫
今天要為大家紹一款由jquery實(shí)現(xiàn)的鼠標(biāo)單擊出現(xiàn)水波特效。用鼠標(biāo)點(diǎn)擊頁面,你可以看到頁面不斷出面水波紋效果。然后水波紋漸漸消失。效果非常不錯2016-04-04
jQuery 如何實(shí)現(xiàn)一個滑動按鈕開關(guān)
本文給大家分享一段jquery代碼實(shí)現(xiàn)滑動按鈕開關(guān)的效果,代碼簡單易懂,非常不錯,具有一定的參考借鑒價值,需要的的朋友參考下2016-12-12

