You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何配置react-tsparticles实现whois.domaintools.com同款鼠标跟随粒子动画

你目前配置的问题出在交互模式选择错误,缺少粒子吸引相关的配置,调整以下参数即可实现鼠标悬停时粒子跟随聚集的效果:

  • 替换hover交互模式:将onHover.mode从["connect","grab"]改为["attract", "grab"],attract模式是实现粒子被鼠标吸引移动的核心能力
  • 新增attract模式配置:在interactivity.modes下添加attract相关参数,控制吸引距离和移动速度
  • 优化粒子基础属性:关闭粒子碰撞检测避免聚集时互相弹开,降低粒子默认移动速度让跟随效果更顺滑,缩小连线距离避免整体画面过乱
  • 效果微调提示:如果觉得粒子跟随的吸引力不足可以调大interactivity.modes.attract.speed,想要粒子聚集范围更大可以调大attract.distance,粒子大小和连线透明度可根据页面背景风格自行调整

修改后的完整配置参考:

<Particles
  id="tsparticles"
  init={particlesInit}
  loaded={particlesLoaded}
  options={{
    fpsLimit: 60,
    interactivity: {
      events: {
        onHover: {
          enable: true,
          mode: ["attract","grab"],
        },
        onClick: {
            enable: false,
        },
        resize: true,
      },
      modes: {
        bubble: {
          distance: 400,
          duration: 1,
          opacity: 0.8,
          size: 40,
        },
        push: {
          quantity: 4,
        },
        repulse: {
          distance: 200,
          duration: 0.4,
        },
        attract: {
          distance: 200,
          duration: 0.4,
          speed: 1
        },
        grab: {
          distance: 180,
          links: {
            opacity: 0.8
          }
        }
      },
    },
    particles: {
      color: {
        value: "#ffffff",
      },
      links: {
        color: "#ffffff",
        distance: 100,
        enable: true,
        opacity: 0.4,
        width: 1,
      },
      collisions: {
        enable: false,
      },
      move: {
        direction: "none",
        enable: true,
        outMode: "bounce",
        random: true,
        speed: 1.5,
        straight: false,
      },
      number: {
        density: {
          enable: true,
          value_area: 800,
        },
        value: 80,
      },
      opacity: {
        value: 0.5,
      },
      shape: {
        type: "circle"
      },
      size: {
        random: true,
        value: 3,
      },
    },
    detectRetina: true,
  }}
/>

内容的提问来源于stack exchange,提问作者Mehdi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 22:36:06