私はjquery(実際にはWebデザイン/開発全体)に新しく、この階層パネルシステムをサイト(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);
に私のコードですが、私は実際のサイトにそれを実装する予定。モバイル版には矢印の代わりにスワイプが表示されます。
基本的に何が起きているのかは、外側のパネルがうまく作業を切り替えることですが、内側のヒーローズリストを切り替えるとします。前回を押すと、2番目の外部クラスの最終内部リストがアクティブに設定されます。次のヒットは正しい第1アウターパネルのインヒーローをセットするが、第2をアクティブにする。両方のインナーパネルに「内部アクティブ」クラスが含まれているためですか?これは前と次の矢印の名前が同じであるためですか?その場合、1つのインスタンスごとにクリック機能を作成する必要がありますか?
ありがとうございます!
変更のために、あなたの.siblings( "。outer:最初")との違いは何ですか? .siblings( "。outer")。first()?構文の優先順位ですか? –
@KyleBenderothはい、私はシンタックスを減らすことを好みます – gaetanoM