fix(animation): 恢复进场动画,不再被 reduced-motion 全局吃掉
根因:clear.css 里从模板继承的 prefers-reduced-motion 规则把所有元素的 transition-duration / animation-duration 强制成 0.01ms。本机(Windows 关闭动画、 VM/RDP 环境)会命中该媒体查询,于是每个过渡都只剩延迟、没有插值——字幕、名次变化、 wipe 全部变成一格一格的瞬移,看起来就是动画被吃掉。 - clear.css:只保留 scroll-behavior 的降级,不再压掉动画时长。这个项目本身 就是动画演示,全局关动画等于关掉产品 - useChyronDirector:把固定的 50ms 定时器换成双 requestAnimationFrame, 保证"闭合帧"真正绘制之后才切到开启状态;隐藏标签页时用定时器兜底 - broadcastGraphicsSlice:修掉 incrementChyronsOpenState 里复制粘贴导致的 二次自增("下一步"会一次跳两级,进场从关闭直接跳到全开) 验证:BaseBlack 的 transition-duration 由 1e-05s 恢复为 0.8s / 0.667s, 不透明度在 825→1690ms 之间逐帧插值(49 个不同值 / 70 帧),控制台无报错。
This commit is contained in:
1 parent
9528307820
commit
f689bb0eeb
3 files changed
+37
-15
No files matched your search
+13
-3
@@ -71,6 +71,19 @@ select {
|
|||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Only the scroll behaviour is reduced here.
|
||||||
|
*
|
||||||
|
* The boilerplate rule that used to live below this also forced
|
||||||
|
* "animation-duration: 0.01ms !important" and "transition-duration: 0.01ms
|
||||||
|
* !important" on every element. That is a sensible default for an ordinary
|
||||||
|
* website, but this project *is* an animation showcase: the chyrons, the
|
||||||
|
* position change flashes and the wipes are the product. On any machine where
|
||||||
|
* the OS reports prefers-reduced-motion (Windows "show animations" switched
|
||||||
|
* off, most VMs and RDP sessions), that rule silently collapsed every entrance
|
||||||
|
* animation into a single frame - it looked like the animation had been eaten,
|
||||||
|
* with the delays still running so the graphic simply snapped into place.
|
||||||
|
*/
|
||||||
@media (prefers-reduced-motion: reduce) {
|
@media (prefers-reduced-motion: reduce) {
|
||||||
html:focus-within {
|
html:focus-within {
|
||||||
scroll-behavior: auto;
|
scroll-behavior: auto;
|
||||||
@@ -79,9 +92,6 @@ select {
|
|||||||
*,
|
*,
|
||||||
*::before,
|
*::before,
|
||||||
*::after {
|
*::after {
|
||||||
animation-duration: 0.01ms !important;
|
|
||||||
animation-iteration-count: 1 !important;
|
|
||||||
transition-duration: 0.01ms !important;
|
|
||||||
scroll-behavior: auto !important;
|
scroll-behavior: auto !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,8 +12,8 @@ import {
|
|||||||
import { BGChyronDriver, BGChyrons, GridSpot } from "../../../types/state";
|
import { BGChyronDriver, BGChyrons, GridSpot } from "../../../types/state";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The chyron animation needs a frame mounted at openState 0 before it is
|
* Safety delay for advancing a freshly mounted chyron. The real trigger is two
|
||||||
* advanced, otherwise the whole transition is skipped.
|
* animation frames; this only fires if frames stop being produced (hidden tab).
|
||||||
*/
|
*/
|
||||||
export const CHYRON_OPEN_DELAY_MS = 50;
|
export const CHYRON_OPEN_DELAY_MS = 50;
|
||||||
|
|
||||||
@@ -75,8 +75,23 @@ export function useChyronDirector() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
dispatch(setChyrons(newChyrons));
|
dispatch(setChyrons(newChyrons));
|
||||||
// Delay a short time and increment the open state so the animation can happen.
|
|
||||||
setTimeout(() => dispatch(incrementChyronsOpenState()), CHYRON_OPEN_DELAY_MS);
|
/**
|
||||||
|
* Mount at openState 0, then let the browser paint that "closed" frame
|
||||||
|
* before flipping to open - a CSS transition needs a painted start value to
|
||||||
|
* interpolate from. Two animation frames guarantee a paint in between; the
|
||||||
|
* old fixed timeout raced it and on a busy machine the whole entrance was
|
||||||
|
* silently skipped.
|
||||||
|
*/
|
||||||
|
let advanced = false;
|
||||||
|
const advance = () => {
|
||||||
|
if (advanced) return;
|
||||||
|
advanced = true;
|
||||||
|
dispatch(incrementChyronsOpenState());
|
||||||
|
};
|
||||||
|
window.requestAnimationFrame(() => window.requestAnimationFrame(advance));
|
||||||
|
// Fallback for a hidden tab, where no frames are produced at all.
|
||||||
|
window.setTimeout(advance, CHYRON_OPEN_DELAY_MS * 4);
|
||||||
}, [dispatch, targetSpots, chyronSettings, buildDriverChyron, grid]);
|
}, [dispatch, targetSpots, chyronSettings, buildDriverChyron, grid]);
|
||||||
|
|
||||||
const next = useCallback(() => {
|
const next = useCallback(() => {
|
||||||
|
|||||||
@@ -37,18 +37,15 @@ export const broadcastGraphicsSlice = createSlice({
|
|||||||
setChyronsOpenState: (state, action: PayloadAction<OpenState>) => {
|
setChyronsOpenState: (state, action: PayloadAction<OpenState>) => {
|
||||||
if (state.chyrons == null) return;
|
if (state.chyrons == null) return;
|
||||||
state.chyrons.openState = action.payload;
|
state.chyrons.openState = action.payload;
|
||||||
|
|
||||||
if (state.chyrons != null) {
|
|
||||||
state.chyrons.openState = action.payload;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* Advances the animation one step. This used to bump the state twice, which
|
||||||
|
* skipped step 1 entirely - the "next step" button jumped two stages and the
|
||||||
|
* entrance went straight from closed to fully open.
|
||||||
|
*/
|
||||||
incrementChyronsOpenState: (state) => {
|
incrementChyronsOpenState: (state) => {
|
||||||
if (state.chyrons == null) return;
|
if (state.chyrons == null) return;
|
||||||
++state.chyrons.openState;
|
++state.chyrons.openState;
|
||||||
|
|
||||||
if (state.chyrons != null) {
|
|
||||||
++state.chyrons.openState;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
clearChyrons: (state) => {
|
clearChyrons: (state) => {
|
||||||
state.chyrons = null;
|
state.chyrons = null;
|
||||||
|
|||||||
Reference in new issue
Block a user