0
3つのアイテムのリストがあります。上/下ボタンをクリックすると、インデックス/アクティブアイテムが変更されます。インデックスがクラス 'ドレイン'を持つ必要があり、インデックスの後に2番目の次の後に、クラス 'unfill'を取得する必要があります。それをクリックすると、インデックスが1であるときに、このリストをループし、次のアイテムを2番目に与えるクラス
次のようになります。
<a href="#" class="active"> Item One </a>
<a href="#" class="drain"> Item Two </a>
<a href="#" class="unfill"> Item Three </a>
インデックスが2のとき:
<a href="#" class="unfill"> Item One </a>
<a href="#" class="active"> Item Two </a>
<a href="#" class="drain"> Item Three </a>
インデックスが3のとき:
<a href="#" class="drain"> Item One </a>
<a href="#" class="unfill"> Item Two </a>
<a href="#" class="active"> Item Three </a>
マイ数学はそれほど良いことではない、誰かがこのループがどのように見えるか教えてくれますか?あなたは「アクティブ」クラスを設定すると
var services = $('header.header-image .services-links a');
var totalServices = services.length;
var arrowUp = $('header.header-image .services .pagination .up');
var arrowDown = $('header.header-image .services .pagination .down');
arrowUp.click(function(event) {
if (index > 1){
index = index - 1;
} else {
index = totalServices;
}
updateActiveClass('up');
});
arrowDown.click(function(event) {
if (index < totalServices){
index = index + 1;
} else {
index = 1;
}
updateActiveClass('down');
});
services.click(function(event) {
event.preventDefault();
thisIndex = $(this).index();
index = thisIndex + 1;
updateActiveClass();
});