🔧 FIX: Растягивание внешней пилюли с улучшенной логикой и ResizeObserver
This commit is contained in:
@@ -704,8 +704,14 @@
|
|||||||
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
|
box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
|
||||||
transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
|
transition: all 0.4s cubic-bezier(0.23, 1, 0.32, 1);
|
||||||
min-width: 60px;
|
min-width: 60px;
|
||||||
|
width: 120px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
transform-origin: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.outer-pill.expanding {
|
||||||
|
transform: scale(1.02);
|
||||||
}
|
}
|
||||||
|
|
||||||
.pill-indicators {
|
.pill-indicators {
|
||||||
@@ -921,19 +927,35 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Анимация внешней pill (растягивается под активный элемент)
|
// Анимация внешней pill (растягивается под активный элемент)
|
||||||
|
setTimeout(() => {
|
||||||
if (outerPill) {
|
if (outerPill) {
|
||||||
const activeIndicator = indicators[index];
|
const activeIndicator = indicators[index];
|
||||||
if (activeIndicator) {
|
if (activeIndicator) {
|
||||||
// Измеряем ширину активного элемента
|
// Даем время для применения стилей активного элемента
|
||||||
const activeRect = activeIndicator.getBoundingClientRect();
|
setTimeout(() => {
|
||||||
const containerRect = outerPill.getBoundingClientRect();
|
// Вычисляем ширину на основе текста
|
||||||
|
const titleElement = activeIndicator.querySelector('.pill-indicator-title');
|
||||||
|
let calculatedWidth = 120; // минимальная ширина
|
||||||
|
|
||||||
// Вычисляем нужную ширину (с учетом padding)
|
if (titleElement && titleElement.textContent) {
|
||||||
const newWidth = Math.max(activeRect.width + 40, 120);
|
// Примерная формула: длина текста * 8px + padding
|
||||||
outerPill.style.width = newWidth + 'px';
|
const textLength = titleElement.textContent.length;
|
||||||
|
calculatedWidth = Math.max(textLength * 8 + 60, 120);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Updating outer pill width to:', calculatedWidth);
|
||||||
|
outerPill.style.width = calculatedWidth + 'px';
|
||||||
outerPill.style.transition = 'all 0.4s cubic-bezier(0.23, 1, 0.32, 1)';
|
outerPill.style.transition = 'all 0.4s cubic-bezier(0.23, 1, 0.32, 1)';
|
||||||
|
|
||||||
|
// Также обновляем ширину контейнера индикаторов
|
||||||
|
const pillIndicators = document.querySelector('.pill-indicators');
|
||||||
|
if (pillIndicators) {
|
||||||
|
pillIndicators.style.transition = 'all 0.4s cubic-bezier(0.23, 1, 0.32, 1)';
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}, 10);
|
||||||
|
|
||||||
currentActiveIndex = index;
|
currentActiveIndex = index;
|
||||||
}
|
}
|
||||||
@@ -941,7 +963,17 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
// Обработчики событий для индикаторов
|
// Обработчики событий для индикаторов
|
||||||
indicators.forEach((indicator, index) => {
|
indicators.forEach((indicator, index) => {
|
||||||
indicator.addEventListener('click', function() {
|
indicator.addEventListener('click', function() {
|
||||||
|
console.log('Clicked indicator:', index);
|
||||||
currentActiveIndex = index;
|
currentActiveIndex = index;
|
||||||
|
|
||||||
|
// Добавляем класс расширения
|
||||||
|
if (outerPill) {
|
||||||
|
outerPill.classList.add('expanding');
|
||||||
|
setTimeout(() => {
|
||||||
|
outerPill.classList.remove('expanding');
|
||||||
|
}, 400);
|
||||||
|
}
|
||||||
|
|
||||||
updatePillState(index);
|
updatePillState(index);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -965,14 +997,41 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
if (carousel) {
|
if (carousel) {
|
||||||
carousel.addEventListener('slide.bs.carousel', function(event) {
|
carousel.addEventListener('slide.bs.carousel', function(event) {
|
||||||
const nextIndex = event.to;
|
const nextIndex = event.to;
|
||||||
|
console.log('Carousel sliding to:', nextIndex);
|
||||||
currentActiveIndex = nextIndex;
|
currentActiveIndex = nextIndex;
|
||||||
|
|
||||||
|
// Добавляем класс расширения при смене слайда
|
||||||
|
if (outerPill) {
|
||||||
|
outerPill.classList.add('expanding');
|
||||||
|
setTimeout(() => {
|
||||||
|
outerPill.classList.remove('expanding');
|
||||||
|
}, 400);
|
||||||
|
}
|
||||||
|
|
||||||
updatePillState(nextIndex);
|
updatePillState(nextIndex);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Инициализируем первое состояние
|
// Инициализируем первое состояние
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
console.log('Initializing pill state...');
|
||||||
updatePillState(0);
|
updatePillState(0);
|
||||||
}, 100);
|
}, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Отслеживаем изменения размеров активного элемента
|
||||||
|
if (window.ResizeObserver) {
|
||||||
|
const resizeObserver = new ResizeObserver(entries => {
|
||||||
|
if (outerPill) {
|
||||||
|
const activeIndicator = indicators[currentActiveIndex];
|
||||||
|
if (activeIndicator && activeIndicator.classList.contains('active')) {
|
||||||
|
updatePillState(currentActiveIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
indicators.forEach(indicator => {
|
||||||
|
resizeObserver.observe(indicator);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Animate elements on scroll
|
// Animate elements on scroll
|
||||||
|
|||||||
Reference in New Issue
Block a user