jQuery圖片輪播的具體實(shí)現(xiàn)
效果如下:
先看一看html代碼,以及對應(yīng)的css代碼:
<div id="scrollPics">
<ul class="slider" >
<li><img src="images/ads/1.gif"/></li>
<li><img src="images/ads/2.gif"/></li>
<li><img src="images/ads/3.gif"/></li>
<li><img src="images/ads/4.gif"/></li>
<li><img src="images/ads/5.gif"/></li>
</ul>
<ul class="num" >
<li class="on">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
#scrollPics{
height: 150px;
width: 100%;
margin-bottom: 10px;
overflow: hidden;
position:relative;
}
.num{
position:absolute;
right:5px;
bottom:5px;
}
#scrollPics .num li{
float: left;
color: #FF7300;
text-align: center;
line-height: 16px;
width: 16px;
height: 16px;
cursor: pointer;
overflow: hidden;
margin: 3px 1px;
border: 1px solid #FF7300;
background-color: #fff;
}
#scrollPics .num li.on{
color: #fff;
line-height: 21px;
width: 21px;
height: 21px;
font-size: 16px;
margin: 0 1px;
border: 0;
background-color: #FF7300;
font-weight: bold;
}
用絕對定位設(shè)置列表 num 的位置,對 li 設(shè)置相關(guān)樣式,on 表示顯示圖片對應(yīng)的數(shù)字列表中 li 的樣式類別。
接下來是 js 代碼:
//滾動廣告
var len = $(".num > li").length;
var index = 0; //圖片序號
var adTimer;
$(".num li").mouseover(function() {
index = $(".num li").index(this); //獲取鼠標(biāo)懸浮 li 的index
showImg(index);
}).eq(0).mouseover();
//滑入停止動畫,滑出開始動畫.
$('#scrollPics').hover(function() {
clearInterval(adTimer);
}, function() {
adTimer = setInterval(function() {
showImg(index)
index++;
if (index == len) { //最后一張圖片之后,轉(zhuǎn)到第一張
index = 0;
}
}, 3000);
}).trigger("mouseleave");
function showImg(index) {
var adHeight = $("#scrollPics>ul>li:first").height();
$(".slider").stop(true, false).animate({
"marginTop": -adHeight * index + "px" //改變 marginTop 屬性的值達(dá)到輪播的效果
}, 1000);
$(".num li").removeClass("on")
.eq(index).addClass("on");
}
- 12款經(jīng)典的白富美型—jquery圖片輪播插件—前端開發(fā)必備
- Jquery代碼實(shí)現(xiàn)圖片輪播效果(一)
- 原生js和jquery實(shí)現(xiàn)圖片輪播特效
- 基于JQuery的實(shí)現(xiàn)圖片輪播效果(焦點(diǎn)圖)
- jquery實(shí)現(xiàn)定時(shí)自動輪播特效
- 原生js和jquery實(shí)現(xiàn)圖片輪播淡入淡出效果
- jquery 實(shí)現(xiàn)輪播圖詳解及實(shí)例代碼
- 利用jquery寫的左右輪播圖特效
- jQuery實(shí)現(xiàn)碎片輪播效果
- jQuery實(shí)現(xiàn)炸裂輪播效果
相關(guān)文章
jquery 動態(tài)創(chuàng)建元素的方式介紹及應(yīng)用
動態(tài)創(chuàng)建元素可以通過兩種方式1、Dom HTml2、JQuery函數(shù)創(chuàng)建3、頁面加載的時(shí)候最好在頁面加載完后執(zhí)行創(chuàng)建,感興趣的朋友可以了解下2013-04-04jQueryeasyui 中如何使用datetimebox 取兩個(gè)日期間相隔的天數(shù)
這篇文章主要介紹了jQueryeasyui 中使用datetimebox 取兩個(gè)日期間相隔的天數(shù),需要的朋友參考下吧2017-06-06當(dāng)jQuery遭遇CoffeeScript的時(shí)候 使用分享
雖然對ruby不太了解,但是看到CoffeeScript詩一般的代碼確實(shí)被怔住了,和jQuery之前給我的感覺是如此的相似——都是一個(gè)字,美,當(dāng)jQuery遭遇到CoffeeScript時(shí),會蹦出什么樣的火花呢?2011-09-09jQery使網(wǎng)頁在顯示器上居中顯示適用于任何分辨率
這篇文章主要介紹了jQery使網(wǎng)頁在任何分辨率的顯示器上居中顯示的方法,需要的朋友可以參考下2014-06-06jquery實(shí)現(xiàn)點(diǎn)擊向下展開菜單項(xiàng)(伸縮導(dǎo)航)效果
這篇文章主要介紹了jquery實(shí)現(xiàn)點(diǎn)擊向下展開菜單項(xiàng)(伸縮導(dǎo)航)效果,通過jquery遍歷及匹配頁面元素并動態(tài)修改頁面元素樣式實(shí)現(xiàn)該功能,需要的朋友可以參考下2015-08-08使用jQuery UI的tooltip函數(shù)修飾title屬性的氣泡懸浮框
使用jQuery UI的tooltip()函數(shù),可以使懸浮提示框不再那么千篇一律,以下是完整的代碼,感興趣的朋友可以參考下哈,希望對大家有所幫助2013-06-06基于jQuery實(shí)現(xiàn)無縫輪播與左右點(diǎn)擊效果
在網(wǎng)頁中我們經(jīng)常會用到無縫輪播左右循環(huán)效果,今天腳本之家小編給大家?guī)砹嘶趈Query實(shí)現(xiàn)無縫輪播與左右點(diǎn)擊效果 ,感興趣的朋友參考下吧2018-05-05jquery實(shí)現(xiàn)疊層3D文字特效代碼分享
本文主要介紹了jquery實(shí)現(xiàn)疊層3D文字特效,實(shí)現(xiàn)很簡單2015-08-08