CSS Transition 回调
问题:
是否可以在以下情况下收到通知CSS 过渡有完成?
答案:
是的,如果浏览器支持,当转换结束时会触发一个事件。不过,具体事件因浏览器而异:
其他注意事项:
代码示例:
const transitionEndEventName = "XXX"; // Determine the appropriate event name const elemToAnimate = ...; // Element to animate let done = false; const transitionEnded = () => { done = true; // Transition finished actions elemToAnimate.removeEventListener(transitionEndEventName, transitionEnded, false); }; elemToAnimate.addEventListener(transitionEndEventName, transitionEnded, false); // Trigger animation setTimeout(() => { if (!done) { console.log("Timeout required to call transition ended."); transitionEnded(); } }, XXX); // Replace XXX with animation duration plus a grace period
注意:
以上是如何检测 CSS 转换是否完成?的详细内容。更多信息请关注PHP中文网其他相关文章!