Scroll Mask Playground
交互式体验 CSS scroll mask 效果,学习如何使用 animation-timeline 创建渐变遮罩效果。
浏览器支持
- Chrome 115+ · 完全支持
- Edge 115+ · 完全支持
- Safari · 实验性支持(需启用功能标志)
- Firefox · 暂不支持
此组件使用 CSS animation-timeline API 实现滚动驱动遮罩效果。如使用不支持此功能的浏览器,遮罩效果可能无法正常显示。
垂直滚动 (通知列表)
参数配置
CSS 代码
.masked-overflow {
--mask-height: 80px;
mask-image: linear-gradient(to top, transparent, currentColor 90%),
linear-gradient(to bottom, transparent 0, currentColor 100%),
linear-gradient(currentColor, currentColor);
mask-size: 100% var(--top-mask-height),
100% var(--bottom-mask-height),
100% 100%;
animation-name: show-top-mask, hide-bottom-mask;
animation-timeline: scroll(self), scroll(self);
animation-range: 0 100%, 0 100%;
animation-fill-mode: both;
mask-position: 0 0, 0 100%, 0 0;
mask-repeat: no-repeat, no-repeat, no-repeat;
mask-composite: exclude;
}
@keyframes show-top-mask {
0% { --top-mask-height: 0px; }
to { --top-mask-height: var(--mask-height); }
}
@keyframes hide-bottom-mask {
0% { --bottom-mask-height: var(--mask-height); }
to { --bottom-mask-height: 0px; }
}水平滚动 (标签云)
参数配置
CSS 代码
.masked-overflow-x {
--mask-width: 80px;
mask-image: linear-gradient(to left, transparent, currentColor 90%),
linear-gradient(to right, transparent, currentColor 100%),
linear-gradient(currentColor, currentColor);
mask-size: var(--left-mask-width) 100%,
var(--right-mask-width) 100%,
100% 100%;
animation-name: show-left-mask, hide-right-mask;
animation-timeline: scroll(self inline), scroll(self inline);
animation-range: 0 100%, 0 100%;
mask-position: 0 0, 100% 0, 0 0;
mask-repeat: no-repeat, no-repeat, no-repeat;
mask-composite: exclude;
}
@keyframes show-left-mask {
0% { --left-mask-width: 0px; }
to { --left-mask-width: var(--mask-width); }
}
@keyframes hide-right-mask {
0% { --right-mask-width: var(--mask-width); }
to { --right-mask-width: 0px; }
}