5种按钮点击粒子爆炸效果

代码语言:html

所属分类:粒子

代码描述:5种按钮点击粒子爆炸效果

代码标签: 粒子 爆炸 效果

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


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
particle {
  position: fixed;
  top: 0;
  left: 0;
  opacity: 0;
  pointer-events: none;
  background-repeat: no-repeat;
  background-size: contain;
}

body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  overflow: hidden;
  text-align: center;
}

button {
  padding: 20px;
  margin: 10px;
  align-self: center;
}

.preloader {
  position: absolute;
  background: url(http://repo.bfw.wiki/bfwrepo/image/5e754fc375408.png);
}
</style>

</head>
<body translate="no">
<div class="wrapper">
<button data-type="square">Square particles</button>
<button data-type="emoji">Emoji particles</button>
<button data-type="mario">Mario particles</button>
<button data-type="shadow">Shadow particles</button>
<button data-type="line">Line particles</button>
</div>
<span class="preloader"></span>

<script>
function pop (e) {
  let amount = 30;
  switch (e.target.dataset.type) {
    case 'shadow':
    case 'line':
      amount = 60;
      break;
  }
  for (let i = 0; i < amount; i++) {
    createParticle(e.clientX, e.clientY + window.scrollY, e.target.dataset.type);
  }
}
function createParticle (x, y, type) {
  const particle = document.createElement('particle');
  document.body.appendChild(particle);
  let width = Math.floor(Math.random() * 30 + 8);
  let height = width;
  let destinationX = (Math.random() - 0.5) * 300;
  let destinationY = (Math.random() - 0.5) * 300;
  let rotation = Math.random() * 520;
  let delay = Math.random() * 200;
  
  switch (type) {
    case 'square':
      particle.style.background = `hsl(${Math.rando.........完整代码请登录后点击上方下载按钮下载查看

网友评论0