Skip to content

Dotted Glow Background

一个支持暗黑模式的动画点状背景组件,带有发光效果。

安装

bash
npx draft-cli vue add dotted-glow-background

使用

基础用法

Dotted Glow Background

vue
<script setup>
import { DottedGlowBackground } from '@draft-ui/vue'
</script>

<template>
  <div style="position: relative; height: 300px;">
    <DottedGlowBackground />
    <div style="position: relative; z-index: 1;">
      <!-- 你的内容 -->
    </div>
  </div>
</template>

你可以通过 props 自定义颜色、动画速度和其他属性。

API

属性类型默认值描述
gapnumber12点之间的距离(像素)。
radiusnumber2每个点的半径(像素)。
colorstring'rgba(0,0,0,0.7)'亮色模式下点的基础颜色。
darkColorstring-暗黑模式下点的基础颜色(默认使用 color)。
glowColorstring'rgba(0, 170, 255, 0.85)'亮色模式下的发光颜色。
darkGlowColorstring-暗黑模式下的发光颜色(默认使用 glowColor)。
colorLightVarstring-亮色模式点颜色的 CSS 变量名。
colorDarkVarstring-暗黑模式点颜色的 CSS 变量名。
glowColorLightVarstring-亮色模式发光颜色的 CSS 变量名。
glowColorDarkVarstring-暗黑模式发光颜色的 CSS 变量名。
opacitynumber0.6画布的整体透明度(0-1)。
backgroundOpacitynumber0径向渐变背景的透明度(0-1)。
speedMinnumber0.4最小动画速度倍数。
speedMaxnumber1.3最大动画速度倍数。
speedScalenumber1全局速度缩放。
animatebooleantrue是否启用动画。

注意事项

  • 组件使用 position: absolute; inset: 0,因此需要放置在一个定位容器内。
  • 内容应该放在一个兄弟元素中,并设置 position: relative 和适当的 z-index 以显示在背景之上。
  • 组件会自动适配暗黑模式(使用 @vueuse/core 的暗黑模式检测)。
  • 使用 ResizeObserver 自动适应容器大小变化。