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

如何为tsParticles粒子链接配置多颜色?粒子颜色方式不生效

解决tsParticles粒子链接无法匹配粒子多色的问题

粒子的多色配置可以直接用颜色数组,但粒子链接的color配置逻辑不同,不能直接套用相同的数组写法。要让链接和粒子使用相同的颜色(包括多色切换和动画),只需修改links部分的配置:

将原来的:

links: {
    enable: true,
    distance: 100,
    color: "random",
    opacity: 1,
    width: 1
},

替换为:

links: {
    enable: true,
    distance: 100,
    color: "match", // 关键修改:用match匹配粒子颜色
    opacity: 1,
    width: 1
},

修改后的完整JS配置代码:

tsParticles.load("tsparticles", {
    particles: {
        number: {
            value: 400
        },
        color: {
            value: ["#03dac6", "#fac561", "#000000"],
            animation: {
                enable: true,
                speed: 40,
                sync: false
            }
        },
        shape: {
            type: "circle",
        },
        size: {
            value: 2,
            random: true,
            animation: {
                enable: true,
                speed: 16,
                minimumValue: 0.1,
                sync: false
            }
        },
        links: {
            enable: true,
            distance: 100,
            color: "match",
            opacity: 1,
            width: 1
        },
        move: {
            enable: true,
        },
    },

    detectRetina: true,
});

这样设置后,粒子链接会自动匹配对应粒子的颜色,包括你设置的多色切换动画,完全和粒子颜色保持一致。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 18:55:29