html粒子爱心源代码
时间: 2024-11-06 07:20:43 浏览: 77
HTML粒子爱心通常是一个简单的CSS和HTML组合效果,用于创建动态的心形图标。下面是一个基本的示例:
```html
<!DOCTYPE html>
<html lang="zh">
<head>
<style>
.heart {
width: 50px;
height: 76px;
position: relative;
}
.heart:before,
.heart:after {
content: "";
position: absolute;
left: 25px;
top: 14px;
border-width: 8px;
border-style: solid;
}
.heart:before {
border-color: transparent red transparent transparent;
}
.heart:after {
border-color: transparent transparent red transparent;
transform: rotate(45deg);
}
</style>
</head>
<body>
<div class="heart"></div>
</body>
</html>
```
这个代码包含一个`<div>`元素,并设置了`.heart`类的样式,通过改变边框的颜色和旋转角度来创建心形图案。你可以将此代码复制到HTML文件中查看效果。
相关问题
vs粒子爱心跳动源代码
以下是使用VS Code编辑器实现粒子爱心跳动的源代码:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Particle Heart</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #000;
}
canvas {
display: block;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var W = window.innerWidth;
var H = window.innerHeight;
canvas.width = W;
canvas.height = H;
var particles = [];
var mouse = {};
var particle_count = 100;
for (var i = 0; i < particle_count; i++) {
particles.push(new particle());
}
canvas.addEventListener('mousemove', track_mouse, false);
function track_mouse(e) {
mouse.x = e.pageX;
mouse.y = e.pageY;
}
function particle() {
this.speed = { x: -2.5 + Math.random() * 5, y: -15 + Math.random() * 10 };
if (mouse.x && mouse.y) {
this.location = { x: mouse.x, y: mouse.y };
}
else {
this.location = { x: W / 2, y: H / 2 };
}
this.radius = 10 + Math.random() * 20;
this.life = 20 + Math.random() * 10;
this.remaining_life = this.life;
this.r = Math.round(Math.random() * 255);
this.g = Math.round(Math.random() * 255);
this.b = Math.round(Math.random() * 255);
}
function draw() {
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = "black";
ctx.fillRect(0, 0, W, H);
ctx.globalCompositeOperation = "lighter";
for (var i = 0; i < particles.length; i++) {
var p = particles[i];
ctx.beginPath();
p.opacity = Math.round(p.remaining_life / p.life * 100) / 100
var gradient = ctx.createRadialGradient(p.location.x, p.location.y, 0, p.location.x, p.location.y, p.radius);
gradient.addColorStop(0, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")");
gradient.addColorStop(0.5, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", " + p.opacity + ")");
gradient.addColorStop(1, "rgba(" + p.r + ", " + p.g + ", " + p.b + ", 0)");
ctx.fillStyle = gradient;
ctx.arc(p.location.x, p.location.y, p.radius, Math.PI * 2, false);
ctx.fill();
p.remaining_life--;
p.radius--;
p.location.x += p.speed.x;
p.location.y += p.speed.y;
if (p.remaining_life < 0 || p.radius < 0) {
particles[i] = new particle();
}
}
}
setInterval(draw, 33);
</script>
</body>
</html>
```
3d粒子爱心代码html码源
创建一个3D立体爱心形状的HTML代码通常涉及到CSS3的transform、perspective以及可能的SVG或者canvas元素。下面是一个简单的例子,使用纯CSS创建一个动态旋转的心形粒子效果:
```html
<!DOCTYPE html>
<html lang="zh">
<head>
<style>
.heart {
position: relative;
width: 200px;
height: 200px;
transform-style: preserve-3d;
perspective: 500px;
}
.heart:before,
.heart:after {
content: '';
position: absolute;
top: 50%;
left: 50%;
width: 70%;
height: 80%;
border-radius: 50% 50% 50% 0;
transform-origin: bottom;
}
.heart:before {
background-color: #FF69B4;
transform: rotateX(-60deg) translateZ(150px);
}
.heart:after {
background-color: #F08080;
transform: rotateX(60deg) translateY(-100%) translateZ(150px);
}
</style>
</head>
<body>
<div class="heart"></div>
</body>
</html>
```
这个代码创建了一个粉色和浅粉的心形,它们围绕中心轴做旋转动画。你可以通过调整颜色、大小、位置、旋转角度等样式属性来自定义爱心。
阅读全文