jquery插件實現(xiàn)輪播圖效果
更新時間:2021年04月27日 08:46:01 作者:阿飛超努力
這篇文章主要為大家詳細(xì)介紹了jquery插件實現(xiàn)輪播圖效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
每天一個jquery插件-jquery插件實現(xiàn)輪播圖,供大家參考,具體內(nèi)容如下
效果如下

代碼部分
.rel{
white-space:nowrap;
overflow-y: hidden;
overflow-x: auto;
}
.rel::-webkit-scrollbar{
height: 0px;
width: 0px;
}
.img{
width: 100%;
height: 100%;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>再做輪播圖</title>
<script src="js/jquery-3.4.1.min.js"></script>
<script src="js/zzlbt.js"></script>
<link href="css/zzlbt.css" rel="stylesheet" type="text/css" />
<style>
*{
margin: 0px;
padding: 0px;
}
#div{
position: fixed;
top: 20px;
left: 20px;
width: 400px;
height: 200px;
border: 1px solid lightgray;
}
.div{
width: 400px;
height: 200px;
float: left;
margin: 10px;
}
</style>
</head>
<body>
<div class="div"></div>
<div class="div"></div>
</body>
</html>
<script>
$(function(){
$(".div").lbt({
data:[
"img/1.png",
"img/2.png",
"img/3.png",
"img/4.png"
]
})
})
</script>
$.prototype.lbt = function(obj) {
obj = obj == undefined ? {} : obj;
obj.time = obj.time==undefined?1000:obj.time;
var that = this;
var $that = $(this);
$that.arr().forEach($item=>{
$item.addClass("rel");
$(function(){
//添加dom
obj.data.forEach(item=>{
var $img = $("<img class='img' src='"+item+"' />");
$img.appendTo($item);
})
//執(zhí)行輪播
var index = 0;
var timer = setInterval(function(){
$item.stop().animate({
'scrollLeft':$item.width()*index+'px'
},500)
index = (index+1)%obj.data.length;
},obj.time)
//一些基本事件,當(dāng)鼠標(biāo)懸浮暫停輪播與下面的軸
})
})
}
$.prototype.arr = function() {
var that = this;
var arr = [];
for (var i = 0; i < that.length; i++) {
var $dom = $(that[i]);
arr.push($dom);
}
return arr;
}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實現(xiàn)電梯導(dǎo)航案例詳解(切換?網(wǎng)頁區(qū)域)
日常生活中用手機,電腦瀏覽網(wǎng)頁時,滑到了頁面下端后想返回頂部 或 跳轉(zhuǎn)到頁面別的版塊,用鼠標(biāo)滾動很麻煩,網(wǎng)頁電梯導(dǎo)航就可以很方便的精準(zhǔn)到達目標(biāo)版塊,本文給大家分享jquery電梯導(dǎo)航案例詳解,感興趣的朋友一起看看吧2022-05-05
今天抽時間給大家整理jquery和ajax的相關(guān)知識
jquery ajax2015-11-11
jquery實現(xiàn)Li滾動時滾動條自動添加樣式的方法
這篇文章主要介紹了jquery實現(xiàn)Li滾動時滾動條自動添加樣式的方法,實例分析了jquery響應(yīng)鼠標(biāo)事件及動態(tài)添加樣式的相關(guān)技巧,需要的朋友可以參考下2015-08-08
sliderToggle在寫jquery的計時器setTimeouter中不生效
sliderToggle在setTimeouter中不生效,還報錯說是發(fā)生了意想不到的錯誤2014-05-05
jQuery插件HighCharts繪制2D金字塔圖效果示例【附demo源碼下載】
這篇文章主要介紹了jQuery插件HighCharts繪制2D金字塔圖效果,結(jié)合實例形式分析了jQuery使用HighCharts插件繪制金字塔圖效果的操作步驟與相關(guān)實現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2017-03-03
jquery實現(xiàn)兩邊飄浮可關(guān)閉的對聯(lián)廣告
可關(guān)閉的左右兩邊漂浮的對聯(lián)廣告代碼jquery特效,寬屏分辨率大于1024px才顯示,當(dāng)用戶點擊關(guān)閉按鈕可以單獨關(guān)閉自己一邊的漂浮的對聯(lián)廣告代碼,juqery對聯(lián)廣告效果感興趣的朋友一起學(xué)習(xí)吧2015-11-11

