重构为左中右三栏卡片切换效果
All checks were successful
continuous-integration/drone/push Build is passing

- 中间显示主卡片,完整展示内容
- 左右两侧显示相邻卡片的部分预览(缩小85%,半透明)
- 切换时右侧卡片滑动到中间成为主卡片
- 同时中间卡片滑动到左侧成为预览
- 左侧卡片向左消失,新的右侧卡片从右边进入
- 所有卡片同步移动,形成流畅的轮播效果
- 动画时长0.6s,使用 cubic-bezier 缓动
- 保持自动播放和交互功能

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yiqiu
2025-11-25 16:06:15 +08:00
parent 817df58b69
commit 8cb6d0cdc9
2 changed files with 148 additions and 92 deletions

View File

@@ -272,29 +272,33 @@ $(function () {
let isAnimating = false;
const autoPlayDuration = 3000; // 3秒自动切换
// 更新所有幻灯片的堆叠状态
function updateStackStates() {
// 获取循环索引
function getCircularIndex(index) {
return ((index % totalSlides) + totalSlides) % totalSlides;
}
// 更新所有幻灯片的位置状态(左中右)
function updateSlidePositions() {
const prevIndex = getCircularIndex(currentIndex - 1);
const nextIndex = getCircularIndex(currentIndex + 1);
$slides.each(function(index) {
const $slide = $(this);
// 移除所有堆叠
$slide.removeClass('stack-1 stack-2 stack-3');
// 移除所有位置
$slide.removeClass('active prev next slide-to-center slide-to-left slide-out-left slide-in-right');
// 如果不是当前激活的,且不在动画中
if (index !== currentIndex && !$slide.hasClass('leaving') && !$slide.hasClass('entering')) {
// 计算相对于当前索引的位置
let offset = index - currentIndex;
if (offset < 0) offset += totalSlides;
// 只显示后面3张卡片的堆叠效果
if (offset === 1) {
$slide.addClass('stack-1');
} else if (offset === 2) {
$slide.addClass('stack-2');
} else if (offset === 3) {
$slide.addClass('stack-3');
}
if (index === currentIndex) {
// 中间主卡片
$slide.addClass('active');
} else if (index === prevIndex) {
// 左侧预览卡片
$slide.addClass('prev');
} else if (index === nextIndex) {
// 右侧预览卡片
$slide.addClass('next');
}
// 其他卡片保持隐藏状态
});
}
@@ -304,40 +308,44 @@ $(function () {
isAnimating = true;
const $currentSlide = $slides.eq(currentIndex);
const $nextSlide = $slides.eq(index);
const oldIndex = currentIndex;
const newIndex = index;
const prevOldIndex = getCircularIndex(oldIndex - 1);
const nextNewIndex = getCircularIndex(newIndex + 1);
// 移除所有动画类和堆叠类
$slides.removeClass('leaving entering stack-1 stack-2 stack-3');
// 移除所有动画类
$slides.removeClass('slide-to-center slide-to-left slide-out-left slide-in-right');
// 添加离开和进入动画
$currentSlide.addClass('leaving');
$nextSlide.addClass('entering');
// 应用切换动画
// 右侧卡片 -> 中间
$slides.eq(newIndex).removeClass('next').addClass('slide-to-center');
// 中间卡片 -> 左侧
$slides.eq(oldIndex).removeClass('active').addClass('slide-to-left');
// 左侧卡片 -> 消失
$slides.eq(prevOldIndex).removeClass('prev').addClass('slide-out-left');
// 新的右侧卡片进入
$slides.eq(nextNewIndex).addClass('slide-in-right');
// 更新按钮
$tabs.removeClass('active');
$tabs.eq(index).addClass('active');
$tabs.eq(newIndex).addClass('active');
// 等待动画完成
setTimeout(function () {
// 移除旧的 active 类
$currentSlide.removeClass('active leaving');
// 添加新的 active 类
$nextSlide.addClass('active').removeClass('entering');
currentIndex = index;
// 更新堆叠状态
updateStackStates();
// 更新当前索引
currentIndex = newIndex;
// 等待动画完成后更新状态
setTimeout(function() {
updateSlidePositions();
isAnimating = false;
}, 800); // 与 CSS 动画时间一致
}, 600); // 与动画时间一致
}
// 切换到下一张
function nextSlide() {
const nextIndex = (currentIndex + 1) % totalSlides;
const nextIndex = getCircularIndex(currentIndex + 1);
switchSlide(nextIndex);
}
@@ -374,7 +382,7 @@ $(function () {
// 初始化
if (totalSlides > 0) {
updateStackStates();
updateSlidePositions();
startAutoPlay();
}
})();