jQuery圖片輪播的具體實現(xiàn)_jquery
來源:懂視網(wǎng)
責(zé)編:小采
時間:2020-11-27 21:13:36
jQuery圖片輪播的具體實現(xiàn)_jquery
jQuery圖片輪播的具體實現(xiàn)_jquery:效果如下: 先看一看html代碼,以及對應(yīng)的css代碼: 代碼如下: 1 2 3 4 5 代碼如下:#scrollPics{ height: 150px; width: 100%; margin-bottom: 10px; overflow: hidden; position:relative;}.num{
導(dǎo)讀jQuery圖片輪播的具體實現(xiàn)_jquery:效果如下: 先看一看html代碼,以及對應(yīng)的css代碼: 代碼如下: 1 2 3 4 5 代碼如下:#scrollPics{ height: 150px; width: 100%; margin-bottom: 10px; overflow: hidden; position:relative;}.num{
效果如下:

先看一看html代碼,以及對應(yīng)的css代碼:
代碼如下:
1 2 3 4 5 代碼如下:
#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); //獲取鼠標懸浮 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 屬性的值達到輪播的效果
}, 1000);
$(".num li").removeClass("on")
.eq(index).addClass("on");
}
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
jQuery圖片輪播的具體實現(xiàn)_jquery
jQuery圖片輪播的具體實現(xiàn)_jquery:效果如下: 先看一看html代碼,以及對應(yīng)的css代碼: 代碼如下: 1 2 3 4 5 代碼如下:#scrollPics{ height: 150px; width: 100%; margin-bottom: 10px; overflow: hidden; position:relative;}.num{