簡單實(shí)現(xiàn)jQuery輪播效果
更新時(shí)間:2017年08月18日 10:06:07 作者:-懶洋洋
這篇文章主要教大家如何簡單實(shí)現(xiàn)jQuery輪播效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了jQuery輪播效果展示的具體代碼,供大家參考,具體內(nèi)容如下
jQ代碼:
在寫jQuery代碼之前一定要先導(dǎo)庫,此處我用的是3.0的庫
<script src="jquery-3.0.0.js"></script>
<script type="text/javascript">
var timer;
$(function() {
//設(shè)置圖片向左移
imgshow();
//點(diǎn)擊暫停按鈕事件
$(".pause").click(function () {
clearInterval(timer);
});
//點(diǎn)擊播放按鈕事件
$(".play").click(function () {
imgshow();
});
//點(diǎn)擊左按鈕
$(".prev").click(function () {
imganimation("left");
});
//點(diǎn)擊右按鈕
$(".next").click(function () {
imganimation("right");
});
function imganimation(res) {
//圖片向左走的輪播
if(res=="right"){
//animate()動畫第一個(gè)li向左移動20%
$(".lilist:first").animate({
"marginLeft": "-20%"
}, 700, "linear", function () {
//這個(gè)li回到原來的位置
$(this).css("marginLeft", "0px");
//將它追加到ul的最后的位置
$(this).appendTo($(".ullist"));
});
//設(shè)置小框的圖片輪播,原理與大框圖片輪播一致
$(".s_lilist:first").animate({
"marginLeft": "-20%"
}, 650, "linear", function () {
$(this).css("marginLeft", "0px");
$(this).appendTo($(".s_ullist"));
});
}else {
//圖片向右走,與向左的原理相同
$(".lilist:first").animate({
"marginLeft": "20%"
}, 700, "linear", function () {
$(this).css("marginLeft", "0px");
$(".lilist:last").prependTo($(".ullist"));
});
$(".s_lilist:first").animate({
"marginLeft": "20%"
}, 650, "linear", function () {
$(this).css("marginLeft", "0px");
$(".s_lilist:last").prependTo($(".s_ullist"));
});
};
};
//默認(rèn)圖片自動向左走
function imgshow() {
timer = setInterval(function (){
imganimation("right");
} , 2000);
};
});
</script>
css樣式:
* {
margin: 0;
padding: 0;
}
.divbg {
width: 100%;
height: 350px;
/*overflow: hidden;*/
position: relative;
}
.mb {
width: 30%;
height: 350px;
background: rgba(0, 0, 0, 0.3);
position: absolute;
}
.mb:first-child {
left: 0px;
}
.mb:nth-child(2) {
right: 0px;
}
.ullist {
width: 200%;
height: 350px;
margin-left: -50%;
}
.lilist {
width: 20%;
height: 350px;
list-style: none;
float: left;
}
.imglist {
width: 100%;
height: 100%;
}
.divblock{
width: 20%;
height: 70%;
border: 4px solid rgba(255, 255, 255, 0.32);
position: absolute;
z-index: 5;
left: 46%;
top: 15%;
overflow: hidden;
}
.s_mb{
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
position: absolute;
z-index: 10;
}
.s_ullist{
width: 500%;
height: 100%;
margin-left: -200%;
}
.s_lilist{
width: 20%;
height: 100%;
list-style: none;
float: left;
}
.s_imglist{
height: 100%;
width: 100%;
}
.s_mb img{
margin-left: 16%;
margin-top: 65%;
cursor: pointer;
}
html樣式:
<div class="divbg">
<div class="divblock">
<div class="s_mb">
<img class="prev" src="./img2/btn_prev.png" />
<img class="pause" src="./img2/btn_pause.png" />
<img class="play" src="./img2/btn_play.png" />
<img class="next" src="./img2/btn_next.png" />
</div>
<ul class="s_ullist">
<li class="s_lilist">
<img class="s_imglist" src="img2/2121.jpg" />
</li>
<li class="s_lilist">
<img class="s_imglist" src="img2/2122.jpg" />
</li>
<li class="s_lilist">
<img class="s_imglist" src="img2/2123.jpg" />
</li>
<li class="s_lilist">
<img class="s_imglist" src="img2/2124.jpg" />
</li>
<li class="s_lilist">
<img class="s_imglist" src="img2/2123.jpg" />
</li>
</ul>
</div>
<div class="mb"></div>
<div class="mb"></div>
<ul class="ullist">
<li class="lilist">
<img class="imglist" src="img2/2121.jpg" />
</li>
<li class="lilist">
<img class="imglist" src="img2/2122.jpg" />
</li>
<li class="lilist">
<img class="imglist" src="img2/2123.jpg" />
</li>
<li class="lilist">
<img class="imglist" src="img2/2124.jpg" />
</li>
<li class="lilist">
<img class="imglist" src="img2/2123.jpg" />
</li>
</ul>
</div>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 12款經(jīng)典的白富美型—jquery圖片輪播插件—前端開發(fā)必備
- 原生js和jquery實(shí)現(xiàn)圖片輪播特效
- jQuery圖片輪播的具體實(shí)現(xiàn)
- Jquery代碼實(shí)現(xiàn)圖片輪播效果(一)
- 基于JQuery的實(shí)現(xiàn)圖片輪播效果(焦點(diǎn)圖)
- 利用jquery寫的左右輪播圖特效
- jquery實(shí)現(xiàn)定時(shí)自動輪播特效
- 原生js和jquery實(shí)現(xiàn)圖片輪播淡入淡出效果
- jQuery插件slides實(shí)現(xiàn)無縫輪播圖特效
- jquery實(shí)現(xiàn)左右無縫輪播圖
相關(guān)文章
JavaScript 如何計(jì)算文本的行數(shù)的實(shí)現(xiàn)
這篇文章主要介紹了JavaScript 如何計(jì)算文本的行數(shù)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09
在JavaScript中創(chuàng)建對象的可行方法小結(jié)
在Web前端開發(fā)中,JavaScript是一門功能強(qiáng)大的語言,其核心之一便是對象的創(chuàng)建與操作,對象是JavaScript中數(shù)據(jù)結(jié)構(gòu)的重要組成部分,本文將深入探討JavaScript中創(chuàng)建對象的各種方法,并結(jié)合代碼示例和實(shí)際開發(fā)經(jīng)驗(yàn)進(jìn)行詳細(xì)講解,需要的朋友可以參考下2025-03-03
深入淺出JSON.parse的實(shí)現(xiàn)方法
眾所周知,JSON.parse方法用于將一個(gè)json字符串轉(zhuǎn)換成由字符串描述的?JavaScript?值或?qū)ο?本文主要為大家介紹了JSON.parse方法的使用,需要的可以參考下2024-04-04
JS利用?clip-path?實(shí)現(xiàn)動態(tài)區(qū)域裁剪功能
這篇文章主要介紹了JS利用?clip-path?實(shí)現(xiàn)動態(tài)區(qū)域裁剪功能,文中主要通過使用 box-shadow 實(shí)現(xiàn),代碼簡單易懂,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-12-12
js中回調(diào)函數(shù)的學(xué)習(xí)筆記
這篇文章主要介紹了js中回調(diào)函數(shù)的相關(guān)知識,需要的朋友可以參考下2014-07-07

