2013
6
30
ul.panelNavi {
margin: 0 auto;
width: 320px;
}
.panelNavi li {
float: left;
text-align: center;
width: 96px;
height: 122px;
margin: 5px;
display:inline-block;
}
.panelNavi li a{
display:block;
}
.panelNavi li a.imgHover{
border:#4ae 3px solid;
}
.panelNavi li a.imgNoHover{
border:#FFF 3px solid;
}
.panelNavi li.active{
border: 4px solid #44AAEE;
margin: 1px;
}
thumbnail.eq(0).addClass("active");
function slideImg(next){
var pos;
if(slideCurrent < next){
pos = imgSize;
}else{
pos = -imgSize;
}
if(next == imgNum){
next = 0;
}else if(next == -1){
next = (imgNum - 1);
}
flickListImg.eq(next).css("margin-left", pos).stop(true, true).animate({marginLeft: "0"}, "fast");
flickListImg.eq(slideCurrent).stop(true, true).animate({marginLeft: -pos}, "fast");
thumbnail.eq(slideCurrent).removeClass("active");
thumbnail.eq(next).addClass("active");
slideCurrent = next;
}
基本的にはページロード時のサムネイル要素の1番最初にactiveクラスを付け、
スライドイベント時の処理にフリックまたはページャークリックの次に表示される画像にactiveクラスを付け、その前の画像に付いてたactiveクラスを削除する記述を追加しました。
デモではホバーされていない画像には背景と同色のボーダーで視覚的に間隔を取っていますが、背景が単色でない場合はCSS側で調整してください。
var autoSlide = true;
var autoSlideTimer = 3000;
if(autoSlide == true){
var loopSwitch = setInterval(loop, autoSlideTimer);
function loop(){
slideImg(imgCurrent + 1);
}
}
function slideImg(next){
if(autoSlide == true){
clearInterval(loopSwitch);
loopSwitch = setInterval(loop, autoSlideTimer);
}
var pos;
if(slideCurrent < next){
pos = imgSize;
}else{
pos = -imgSize;
}
if(next == imgNum){
next = 0;
}else if(next == -1){
next = (imgNum - 1);
}
flickListImg.eq(next).css("margin-left", pos).stop(true, true).animate({marginLeft: "0"}, "fast");
flickListImg.eq(slideCurrent).stop(true, true).animate({marginLeft: -pos}, "fast");
thumbnail.eq(slideCurrent).removeClass("active");
thumbnail.eq(next).addClass("active");
slideCurrent = next;
}
