if (lastclicked == 'undefined'){
$('#Info-Side-Tabs a:#Main').parent().addClass('active');
} else {
$('#Info-Side-Tabs a:lastclicked').parent().addClass('active');
}
lastclicked は、サイド タブ スイッチャーで最後にクリックしたリンクを教えてくれます。表示/非表示をクリックしても変更されません。私がやろうとしているのは、タブをクリックせずにタブを非表示にすると、アクティブなクラスは閉じる/開くタブに切り替わりますが、コンテンツは変更されません。そのため、lastclicked が定義されていない場合は、他の何もクリックしていないため、再度開いたときにアクティブなタブがデフォルトに戻ります。未定義でない場合は同じ状況ですが、現在、アクティブなクラスが戻るタブが 2 つある可能性があります。
私の完全な JQuery コード:
$('#Info-Side-Tabs a').click(function() {
var clicked = $(this).attr('href');
if (clicked == "#Map-Selection-Info-Close") {
$('#Info-Side-Tabs li').removeClass('active');
$(this).parent().addClass('active');
$(this).attr("href","#Map-Selection-Info-Open");
$(this).text('Open Me');
$('#Map-Selection-Info').animate({marginLeft: '978px'}, 1000);
$('#ATWI80C-Map').animate({width: '900px' }, 1000);
} else if (clicked == "#Map-Selection-Info-Open") {
$(this).parent().removeClass('active');
$(this).attr("href","#Map-Selection-Info-Close");
$(this).text('Close Me');
$('#Map-Selection-Info').animate({marginLeft: '670px'}, 1000);
$('#ATWI80C-Map').animate({width: '600px' }, 1000);
if (lastclicked == 'undefined'){
$('#Info-Side-Tabs a:#Main').parent().addClass('active');
} else {
$('#Info-Side-Tabs a:lastclicked').parent().addClass('active');
}
} else {
lastclicked = clicked;
switchback = $('clicked');
$('#Info-Side-Tabs li').removeClass('active');
$(this).parent().addClass('active');
var activeTab = $(this).attr('href');
$('#tab-content > div:visible').hide();
$(activeTab).show();
}
//alert(lastclicked);
});
私はあらゆる種類を試しましたが、これは現在の試みです。
ライブ ビュー: https://tornhq.com/WorkingOn/InteractiveMap/implementing.html#Map-Selection-Info-Close