Web动画与语音API的实用指南
1. 动画DOM插入与移除
1.1 显示元素动画
可以使用淡入动画显示刚添加到DOM的元素。示例代码如下:
/**
* Shows an element that was just added to the DOM with a fade-in animation.
* @param element The element to show
*/
function showElement(element) {
document.body.appendChild(element);
element.animate([
{ opacity: 0 },
{ opacity: 1 }
], {
// Animate for 250 milliseconds.
duration: 250
});
}
此函数将元素添加到DOM后,执行250毫秒的淡入动画。
1.2 移除元素动画
移除元素时,先运行淡出动画,动画完成后再从DOM中移除元素。示例代码如下:
/**
* Removes an element from the DOM after performing a fade-out animation.
* @param element The element to remove
*/
async function removeElement(element)
超级会员免费看
订阅专栏 解锁全文
1503

被折叠的 条评论
为什么被折叠?



