最新
动画Fade In On Scroll
Content that fades and rises into place as it enters the viewport.
#scroll#reveal#fade
6 个框架中级
A button that spawns a material-style ripple from the click point.
<style>
@keyframes ripple { to { transform: scale(2.4); opacity: 0; } }
</style>
<button type="button" class="ripple-btn relative overflow-hidden rounded-lg bg-blue-600 px-5 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-blue-700 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-600 focus-visible:ring-offset-2">
Click me
</button>
<script>
(function () {
var btn = document.querySelector('.ripple-btn');
if (!btn) return;
var reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
btn.addEventListener('click', function (e) {
if (reduce) return;
var rect = btn.getBoundingClientRect();
var size = Math.max(rect.width, rect.height);
var span = document.createElement('span');
span.style.cssText =
'position:absolute;border-radius:9999px;background:rgba(255,255,255,0.4);pointer-events:none;width:' +
size + 'px;height:' + size + 'px;left:' + (e.clientX - rect.left - size / 2) +
'px;top:' + (e.clientY - rect.top - size / 2) + 'px;animation:ripple 600ms ease-out forwards';
btn.appendChild(span);
setTimeout(function () { span.remove(); }, 600);
});
})();
</script>| Prop | 类型 | 默认值 | 说明 |
|---|---|---|---|
children必填 | ReactNode | - | 在组件内部渲染的内容。 |
onClick | (e: MouseEvent) => void | - | 用户激活控件时触发。 |
className | string | '' | 合并到根元素上的额外类名。 |
The ripple is scaled to the button and scoped to it - never the document. Reduced motion skips the ripple while the click still fires.