nativegallery/static/js/changeTab.js

40 lines
1.1 KiB
JavaScript
Raw Normal View History

2025-02-14 19:55:09 +03:00
function changeTab(id) {
const $activeTabs = $('.v-tab-b.v-tab--active');
const $activeBlocks = $('.active__block');
2025-02-15 04:53:38 +03:00
const $newTab = $('#' + id);
2025-02-14 19:55:09 +03:00
if ($activeTabs.length) {
$activeTabs.removeClass('v-tab--active');
}
2025-02-15 04:53:38 +03:00
$newTab.addClass('v-tab--active');
2025-02-14 19:55:09 +03:00
if ($activeBlocks.length) {
2025-02-15 04:53:38 +03:00
$activeBlocks.stop(true, true).animate({
2025-02-14 19:55:09 +03:00
opacity: 0,
}, 200, function () {
$(this).css('display', 'none').removeClass('active__block');
2025-02-15 04:53:38 +03:00
const $newBlock = $('#' + id + '__block');
$newBlock.css({
2025-02-14 19:55:09 +03:00
display: 'block',
opacity: 0
}).animate({
opacity: 1
}, 150, function () {
$(this).addClass('active__block');
});
});
2025-02-15 04:53:38 +03:00
} else {
// Если нет активных блоков, сразу показываем новый блок
$('#' + id + '__block').css({
display: 'block',
opacity: 0
}).animate({
opacity: 1
}, 150, function () {
$(this).addClass('active__block');
});
2025-02-14 19:55:09 +03:00
}
2025-02-15 04:53:38 +03:00
}