🚀 个人主页 极客小俊
✍🏻 作者简介:程序猿、设计师、技术分享
🐋 希望大家多多支持, 我们一起学习和进步!
🏅 欢迎评论 ❤️点赞💬评论 📂收藏 📂加关注
废话不多说~,直接进入今天的主题…
DeepSeek官网
代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>情人节特效</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<canvas id="valentinesCanvas"></canvas>
<div class="heart"></div>
<script src="script.js"></script>
</body>
</html>
body, html {
margin: 0;
padding: 0;
height: 100%;
overflow: hidden;
background: #000;
}
canvas {
position: absolute;
width: 100%;
height: 100%;
}
.heart {
position: absolute;
top: 50%;
left: 50%;
width: 100px;
height: 90px;
margin-top: -45px;
margin-left: -50px;
background-color: red;
transform: rotate(-45deg);
animation: beat 1.4s linear infinite;
}
.heart::before,
.heart::after {
content: '';
position: absolute;
width: 100px;
height: 90px;
background-color: red;
border-radius: 50%;
}
.heart::before {
top: -45px;
left: 0;
}
.heart::after {
top: 0;
left: 45px;
}
@keyframes beat {
0%, 100% {
transform: rotate(-45deg) scale(1);
}
50% {
transform: rotate(-45deg) scale(1.1);
}
}
const canvas = document.getElementById('valentinesCanvas');
const ctx = canvas.getContext('2d');
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
let particlesArray;
class Particle {
constructor(x, y, directionX, directionY, size, color) {
this.x = x;
this.y = y;
this.directionX = directionX;
this.directionY = directionY;
this.size = size;
this.color = color;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false);
ctx.fillStyle = this.color;
ctx.fill();
}
update() {
if (this.x + this.size > canvas.width || this.x - this.size < 0) {
this.directionX = -this.directionX;
}
if (this.y + this.size > canvas.height || this.y - this.size < 0) {
this.directionY = -this.directionY;
}
this.x += this.directionX;
this.y += this.directionY;
this.draw();
}
}
function init() {
particlesArray = [];
let numberOfParticles = (canvas.height * canvas.width) / 9000;
for (let i = 0; i < numberOfParticles; i++) {
let size = (Math.random() * 5) + 1;
let x = (Math.random() * ((innerWidth - size * 2) - (size * 2)) + size * 2);
let y = (Math.random() * ((innerHeight - size * 2) - (size * 2)) + size * 2);
let directionX = (Math.random() * 5) - 2.5;
let directionY = (Math.random() * 5) - 2.5;
let color = '#E91E63';
particlesArray.push(new Particle(x, y, directionX, directionY, size, color));
}
}
function animate() {
requestAnimationFrame(animate);
ctx.clearRect(0, 0, innerWidth, innerHeight);
for (let i = 0; i < particlesArray.length; i++) {
particlesArray[i].update();
}
}
window.addEventListener('resize', () => {
canvas.width = innerWidth;
canvas.height = innerHeight;
init();
});
init();
animate();
效果
"👍点赞" "✍️评论" "收藏❤️"
欢迎一起交流学习❤️❤️💛💛💚💚
好玩 好用 好看
的干货教程可以
点击下方关注❤️
微信公众号❤️
说不定有意料之外的收获哦..🤗嘿嘿嘿、嘻嘻嘻🤗!
🌽🍓🍎🍍🍉🍇