以下是自己整理的一份演示程式碼,結合了兩個範例的寫法,希望能給需要的朋友一點參考。
.focus-item ul li.item {
text-align: center;
}
.scroll-area .prev, .scroll-area .next {
position: absolute;
bottom: 590px;
width: 29px;
height: 64px;
opacity: 0.6;
overflow: hidden;
display: none;
text-indent: -999px;
border: medium none;
background: url('/images/arrowLR.png') no-repeat scroll 0% 0% transparent;
}
.scroll-area .prev {
left: 0px;
background-position: -50px 0px;
}
.scroll-area .next {
right: 0px;
}
.scroll-area .bdOn .prev, .scroll-area .bdOn .next {
display: block;
}
.scroll-area .focus-hd {
left: 63px;
position: absolute;
}
.focus-hd .sNext, .focus-hd .sPrev {
float: left;
display: block;
width: 14px;
height: 47px;
text-indent: -9999px;
background: url('/images/sprites1008.png') no-repeat scroll 0px -3046px transparent;
}
.focus-hd .sNext {
background-position: 0px -2698px;
}
.focus-hd .show_bottom_nav {
float: left;
margin: 0px 6px;
display: inline;
width: 832px;
overflow: hidden;
}
.focus-hd .show_bottom_nav ul li {
margin-left: 15px;
}
這裡有個小技巧值得注意:.prev 與 .next 預設是 display: none,只有滑鼠移入 .focus-item 時,透過 JS 加上 bdOn 這個 class 才會顯示。如此一來,大圖的左右箭頭平時不佔視覺空間,需要時才浮現。
<div class="scroll-area">
<div class="focus-item">
<ul>
<li data-bottom-thumb="/attachments/news_gallery/20140528162328_454.jpg" class="item" data-text-id="#thumbTxt1">
<img src="/attachments/news_gallery/20140528162328_454.jpg" alt="標題1" />
</li>
<li data-bottom-thumb="/attachments/news_gallery/20140528162328_733.jpg" class="item" data-text-id="#thumbTxt2">
<img src="/attachments/news_gallery/20140528162328_733.jpg" alt="標題2" />
</li>
</ul>
<a class="prev" href="javascript:void(0)"></a>
<a class="next" href="javascript:void(0)"></a>
</div>
<div class="focus-hd">
<a class="sPrev prevStop" href="javascript:void(0)">←</a>
<div class="show_bottom_nav">
<ul>
<li data-bottom-thumb="/attachments/news_gallery/20140528162328_454.jpg" class="item" data-text-id="#thumbTxt1" style="float: left">
<img style="width: 150px;height: 100px" src="/attachments/news_gallery/20140528162328_454.jpg" alt="標題1" />
</li>
<li data-bottom-thumb="/attachments/news_gallery/20140528162328_733.jpg" class="item" data-text-id="#thumbTxt2" style="float: left">
<img style="width: 150px;height: 100px" src="/attachments/news_gallery/20140528162328_733.jpg" alt="標題2" />
</li>
</ul>
</div>
<a class="sNext" href="javascript:void(0)">→</a>
</div>
</div>
結構分成兩塊:.focus-item 是主視覺的大圖區,.focus-hd 則是下方的縮圖導覽列。兩者用同一份資料驅動,點縮圖就能切換大圖。
// 大圖輪播:以 focus-hd 的 li 作為分頁觸發點,主體是 focus-item ul
jQuery(".scroll-area").slide({
titCell: '.focus-hd li',
mainCell: '.focus-item ul',
delayTime: 0,
trigger: 0,
autoPlay: true
});
// 滑入時加上 bdOn,讓左右箭頭浮現
jQuery(".scroll-area .focus-item").hover(function () {
jQuery(this).addClass("bdOn");
}, function () {
jQuery(this).removeClass('bdOn');
});
// 縮圖導覽列本身的橫向滾動
jQuery(".scroll-area .show_bottom_nav").slide({
mainCell: "ul",
delayTime: 100,
vis: 5,
effect: "left",
autoPage: true,
prevCell: ".sPrev",
nextCell: ".sNext"
});
titCell 指定「分頁按鈕」在哪裡,mainCell 指定要滾動的內容;vis 控制一次顯示幾項;effect 決定切換方式(left 為橫向滑動);autoPage 會依子元素數量自動產生分頁索引;prevCell 與 nextCell 則綁定自訂的箭頭元素。更多效果可對照 SuperSlide 官方文件調整。