js彩色雨滴下雨动画效果代码

代码语言:html

所属分类:粒子

代码描述:js彩色雨滴下雨动画效果代码

代码标签: 下雨 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<html lang="en"><head>

 
<meta charset="UTF-8">
 

 
 
 
 
<style>
* {
 
box-sizing: border-box;
}
body
{
 
background-color: black;
 
transition: background-color 1000ms linear;
}
canvas
{
 
position: absolute;
 
top: 0;
 
left: 0;
 
width: 100%;
 
height: 100%;
}
footer
{
 
position: absolute;
 
height: 50px;
 
left: 0;
 
bottom: 0;
 
width: 100%;
 
text-align: right;
 
padding: 10px;
 
color: grey;
 
font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono,
    DejaVu Sans Mono
, Bitstream Vera Sans Mono, Courier New, monospace, serif;
}
</style>




</head>

<body>
 
<canvas id="main" width="834" height="518"></canvas>
<canvas id="middle" width="834" height="518"></canvas>
<canvas id="final" width="834" height="518"></canvas>
<footer>
 
<span>
   
<p>@weirdyang</p>
 
</span>
</footer>

 
     
<script >
// mouse
const mouse = {
  x: 0,
  y: 0,
  prevX: 0,
  prevY: 0,
  dead: false,
  right() {
    return this.x >= this.prevX;
  } };

const movements = ["touchstart", "mousemove", "touchmove"];
const leaves = ["touchend", "mouseleave", "mouseout"];
function updateMouse(x, y) {
  mouse.prevX = mouse.dead ? 0 : mouse.x;
  mouse.prevY = mouse.dead ? 0 : mouse.y;

  mouse.x = x;
  mouse.y = y;
}
function setUpEvent() {
  movements.forEach(move => {
    window.addEventListener(move, function (event) {
      event.preventDefault();
      const { x, y } = getMousePos(canvas, event, mouse);
      mouse.dead = false;
      updateMouse(x, y);
    });
  });
  leaves.forEach(move => {
    window.addEventListener(move, function (event) {
      event.preventDefault();
      updateMouse(0, 0);
      mouse.dead = true;
    });
  });
}

///https://levelup.gitconnected.com/using-prototype-vs-this-in-a-javascript-class-can-help-save-memory-816636418c3e
const colors = [
{
  canvas: document.getElementById("main"),
  context: document.getElementById("main").getContext("2d"),
  drops: [],
  color: "#00FFFC",
  speed: 1.5,
  radius: 1 },

{
  canvas: document.getElementById("middle"),
  context: document.getElementById("middle").getContext(&.........完整代码请登录后点击上方下载按钮下载查看

网友评论0