修复翻页时钟动画效果
- 修正下半翻转片动画方向:从 -90° 向下翻转至 0° - 移除透明度渐变,依靠 backface-visibility 实现硬切换效果 - 简化 transform 计算,使用 CSS transform-origin 控制旋转轴 - 调整层级确保上半翻转片在下半翻转片之上 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4518e2e57e
commit
a3d4012064
@ -69,7 +69,8 @@
|
|||||||
border-top-left-radius: 4px;
|
border-top-left-radius: 4px;
|
||||||
border-top-right-radius: 4px;
|
border-top-right-radius: 4px;
|
||||||
backface-visibility: hidden;
|
backface-visibility: hidden;
|
||||||
z-index: 10;
|
z-index: 11;
|
||||||
|
/* 旋转轴在底部边缘(卡片中线位置) */
|
||||||
transform-origin: center bottom;
|
transform-origin: center bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,6 +88,7 @@
|
|||||||
border-bottom-right-radius: 4px;
|
border-bottom-right-radius: 4px;
|
||||||
backface-visibility: hidden;
|
backface-visibility: hidden;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
/* 旋转轴在顶部边缘(卡片中线位置) */
|
||||||
transform-origin: center top;
|
transform-origin: center top;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,14 +42,16 @@ export function FlipDigit({ value, size }: FlipDigitProps) {
|
|||||||
|
|
||||||
// Start bottom animation after top completes
|
// Start bottom animation after top completes
|
||||||
const startBottomAnimation = (targetValue: number) => {
|
const startBottomAnimation = (targetValue: number) => {
|
||||||
|
// 上半片翻转完成后,更新上半翻转片的值为新值
|
||||||
|
// 这样当 finishAnimation 重置 rotation 时,上半翻转片显示正确的值
|
||||||
setFlipTopValue(targetValue);
|
setFlipTopValue(targetValue);
|
||||||
|
|
||||||
// Animate bottom flap from -90deg to 0deg
|
// 第二阶段:下半片从-90°向下翻转90°到0°
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
setBottomRotation(0);
|
setBottomRotation(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
// After bottom animation completes, update bgBottom and finish
|
// 下半片翻转完成后,背景下半更新为新值
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setBgBottomValue(targetValue);
|
setBgBottomValue(targetValue);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -109,14 +111,12 @@ export function FlipDigit({ value, size }: FlipDigitProps) {
|
|||||||
|
|
||||||
const topFlipStyle = {
|
const topFlipStyle = {
|
||||||
height: `${halfHeight}px`,
|
height: `${halfHeight}px`,
|
||||||
transform: `perspective(1000px) translateY(${halfHeight * 0.5}px) rotateX(${topRotation}deg) translateY(${-halfHeight * 0.5}px)`,
|
transform: `perspective(1000px) rotateX(${topRotation}deg)`,
|
||||||
opacity: topRotation > 60 ? 0 : 1,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const bottomFlipStyle = {
|
const bottomFlipStyle = {
|
||||||
height: `${halfHeight}px`,
|
height: `${halfHeight}px`,
|
||||||
transform: `perspective(1000px) translateY(${-halfHeight * 0.5}px) rotateX(${bottomRotation}deg) translateY(${halfHeight * 0.5}px)`,
|
transform: `perspective(1000px) rotateX(${bottomRotation}deg)`,
|
||||||
opacity: bottomRotation > -60 ? 1 : 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const centerLineStyle = {
|
const centerLineStyle = {
|
||||||
@ -145,7 +145,7 @@ export function FlipDigit({ value, size }: FlipDigitProps) {
|
|||||||
style={{
|
style={{
|
||||||
...halfHeightStyle,
|
...halfHeightStyle,
|
||||||
...topFlipStyle,
|
...topFlipStyle,
|
||||||
transition: isAnimating ? 'transform 300ms ease-in, opacity 300ms ease-in' : 'none',
|
transition: isAnimating ? 'transform 300ms ease-in' : 'none',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="flip-digit-text flip-digit-top-text" style={topTextStyle}>
|
<span className="flip-digit-text flip-digit-top-text" style={topTextStyle}>
|
||||||
@ -160,7 +160,7 @@ export function FlipDigit({ value, size }: FlipDigitProps) {
|
|||||||
style={{
|
style={{
|
||||||
...halfHeightStyle,
|
...halfHeightStyle,
|
||||||
...bottomFlipStyle,
|
...bottomFlipStyle,
|
||||||
transition: isAnimating ? 'transform 300ms ease-out, opacity 300ms ease-out' : 'none',
|
transition: isAnimating ? 'transform 300ms ease-out' : 'none',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="flip-digit-text flip-digit-bottom-text" style={bottomTextStyle}>
|
<span className="flip-digit-text flip-digit-bottom-text" style={bottomTextStyle}>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user