Javascript:不确定如何将颜色样式与动画画布代码分开(?)

时间:2018-02-01 02:20:40

标签: javascript jquery canvas

我已经修改了这个动画画布脚本以满足我的需求。我现在要做的是将指定当前颜色为红色的动画三角形的颜色的代码分离成一个单独的....这样,脚本将被设置为在任何基于标题的页面上运行,但是在背景中移动的三角形的实际颜色可以基于特定页面来设置,例如如果页面的主题为https://wiredintel.jimdo.com/environment。我已经尝试了多种方法来隔离指定三角形颜色的底部,遗憾的是我还没有找到一个可行的解决方案。如果有人可以提供帮助,我们将非常感谢,谢谢。

除HTML和CSS部分之外的代码

missing

小提琴http://jsfiddle.net/zachreynolds/h0tw67jo/

1 个答案:

答案 0 :(得分:0)

这在一定程度上解决了这个问题,但与鼠标的交互性停止了工作。

<script>
/* <![CDATA[ */
window.onpageshow=function(){
particlesJS("particles-js", {
  "particles": {
    "number": {
      "value": 50,
      "density": {
        "enable": true,
        "value_area": 600
      }
    },
    "color": {
      "value": "#f00"
    },
    "shape": {
      "type": "triangle",
      "stroke": {
        "width": 0,
        "color": "#000000"
      },
      "polygon": {
        "nb_sides": 5
      },
      "image": {
        "src": "img/github.svg",
        "width": 100,
        "height": 100
      }
    },
    "opacity": {
      "value": 0.5,
      "random": false,
      "anim": {
        "enable": false,
        "speed": 1,
        "opacity_min": 0.1,
        "sync": false
      }
    },
    "size": {
      "value": 7,
      "random": true,
      "anim": {
        "enable": false,
        "speed": 40,
        "size_min": 0.1,
        "sync": false
      }
    },
    "line_linked": {
      "enable": true,
      "distance": 200,
      "color": "#000",
      "opacity": 0.75,
      "width": 1.3
    },
    "move": {
      "enable": true,
      "speed": 1,
      "direction": "none",
      "random": false,
      "straight": false,
      "out_mode": "out",
      "bounce": false,
      "attract": {
        "enable": false,
        "rotateX": 600,
        "rotateY": 1200
      }
    }
  },
  "interactivity": {
    "detect_on": "canvas",
    "events": {
      "onhover": {
        "enable": true,
        "mode": "grab"
      },
      "onclick": {
        "enable": true,
        "mode": "push"
      },
      "resize": true
    },
    "modes": {
      "grab": {
        "distance": 200,
        "line_linked": {
          "opacity": 1
        }
      },
      "bubble": {
        "distance": 400,
        "size": 40,
        "duration": 2,
        "opacity": 8,
        "speed": 3
      },
      "repulse": {
        "distance": 200,
        "duration": 0.4
      },
      "push": {
        "particles_nb": 2
      },
      "remove": {
        "particles_nb": 2
      }
    }
  },
  "retina_detect": true
});
}
/*]]>*/
</script>

https://codepen.io/zachreynolds/pen/NyGBpj