我是jquery(實際上,一般網頁設計/開發)的新手,並且試圖讓這個層級面板系統進入一個站點(90%通過手機訪問)。我非常接近,但我似乎無法說出我的問題在線很好。jquery .next()和.prev()在同一個div內
這是我上的jsfiddle https://jsfiddle.net/o7x4r67w/1/
var main = function() {
"use strict";
// Outer next arrow click
$('.out-arrow-next').click(function() {
// transition to the next outer slide
var currentOuterSlide = $('.outer-active');
var nextOuterSlide = currentOuterSlide.next();
// reset to the beginning if we've reached the end
if (nextOuterSlide.length === 0) {
nextOuterSlide = $('.outer').first(".outer");
}
currentOuterSlide.hide(200).removeClass('outer-active');
nextOuterSlide.show(200).addClass('outer-active');
});
// Outer prev arrow click
$('.out-arrow-prev').click(function() {
// transition to the prevous outer slide
var currentOuterSlide = $('.outer-active');
var prevOuterSlide = currentOuterSlide.prev(".outer");
// reset to the end if we've reached the beginning
if (prevOuterSlide.length === 0) {
prevOuterSlide = $('.outer').last();
}
currentOuterSlide.hide(200).removeClass('outer-active');
prevOuterSlide.show(200).addClass('outer-active');
});
// Inner next arrow click
$('.in-arrow-next').click(function() {
// transition to the next inner slide
var currentinnerSlide = $('.inner-active');
var nextinnerSlide = currentinnerSlide.next();
// reset to the beginning if we've reached the end
if (nextinnerSlide.length === 0) {
nextinnerSlide = $('.inner').first(".inner");
}
currentinnerSlide.hide(200).removeClass('inner-active');
nextinnerSlide.show(200).addClass('inner-active');
});
// Inner prev arrow click
$('.in-arrow-prev').click(function() {
// transition to the previous inner slide
var currentinnerSlide = $('.inner-active');
var previnnerSlide = currentinnerSlide.prev(".inner");
// reset to the end if we've reached the beginning
if (previnnerSlide.length === 0) {
previnnerSlide = $('.inner').last();
}
currentinnerSlide.hide(200).removeClass('inner-active');
previnnerSlide.show(200).addClass('inner-active');
});
};
$(document).ready(main);
這只是一個小項目,拿到嵌套旋轉木馬般建立正常工作的代碼,然後我計劃將其落實到實際的站點。移動版本將有一個滑動而不是箭頭。
基本上發生了什麼是外面板切換工作就好了,但說我切換內心的'英雄'名單。點擊前面將設置第二個外部類的最終內部列表爲激活狀態。接下來擊中將設置正確的第一外板的內心英雄,但也將第二個設置爲激活。這是因爲我的內部面板都包含「內部活動」類嗎?或者是因爲上一個和下一個箭頭被命名爲相同?如果是這樣的話,這是否意味着我不得不爲每個實例創建一個點擊功能?
在此先感謝!
對於您所做的更改,您的.siblings(「。outer:first」)之間的區別是什麼?和.siblings(「。outer」)。first()?它只是語法偏好? –
@KyleBenderoth是的,我更喜歡縮減語法 – gaetanoM