HTML点击鼠标动态特效,屏幕生成特效火花特效

效果视频:

火花视频html+js

直接上代码:

<!DOCTYPE html>
<html>
<head>
	<title>Mouse Click Effect</title>
	<style>
		body {
			margin: 0;
			padding: 0;
			background-color: #000;
		}
		canvas {
			position: absolute;
			top: 0;
			left: 0;
			z-index: -1;
		}
	</style>
</head>
<body>
	<canvas id="canvas"></canvas>
	<script>
		var canvas = document.getElementById("canvas");
		canvas.width = window.innerWidth;
		canvas.height = window.innerHeight;
		var ctx = canvas.getContext("2d");
		var particles = [];
		var particleCount = 100;
		var particleRadius = 3;
		var colors = ["#f44336", "#e91e63", "#9c27b0", "#673ab7", "#3f51b5", "#2196f3", "#03a9f4", "#00bcd4", "#009688", "#4caf50", "#8bc34a", "#cddc39", "#ffeb3b", "#ffc107", "#ff9800", "#ff5722", "#795548", "#9e9e9e", "#607d8b"];
		canvas.addEventListener("mousedown", function(e) {
			for (var i = 0; i < particleCount; i++) {
				particles.push(new createParticle(e.clientX, e.clientY));
			}
		});
		function createParticle(x, y) {
			this.x = x;
			this.y = y;
			this.vx = Math.random() * 10 - 5;
			this.vy = Math.random() * 10 - 5;
			this.color = colors[Math.floor(Math.random() * colors.length)];
			this.radius = particleRadius;
			this.alpha = 1;
			this.draw = function() {
				ctx.globalAlpha = this.alpha;
				ctx.beginPath();
				ctx.arc(this.x, this.y, this.radius, 0, Math.PI * 2, false);
				ctx.fillStyle = this.color;
				ctx.fill();
			}
		}
		function draw() {
			ctx.clearRect(0, 0, canvas.width, canvas.height);
			for (var i = 0; i < particles.length; i++) {
				particles[i].x += particles[i].vx;
				particles[i].y += particles[i].vy;
				particles[i].alpha -= 0.01;
				if (particles[i].alpha <= 0) {
					particles.splice(i, 1);
				} else {
					particles[i].draw();
				}
			}
			requestAnimationFrame(draw);
		}
		draw();
	</script>
</body>
</html>

  • 18
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YCY^v^

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值