废话不多说直接上代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>圣诞树</title>
<script src="./JS/vue.min.js"></script>
<style>
#can {
position: absolute;
top: 0px;
left: 0px;
color: white;
}
body {
background-color: black;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
transform-style: preserve-3d;
/* perspective: 1200px; */
background-image: url(./img/525.jpg);
background-size: 100% 100%;
background-origin: content-box;
animation: tp 25s linear infinite alternate 1s;
}
@keyframes tp {
0%{
background-size: 100% 100%;
}
100%{
background-size: 120% 120%;
}
}
.act {
position: absolute;
background-color: white;
width: 300px;
height: 300px;
-webkit-clip-path: polygon(50% 0, 0% 100%, 100% 100%);
clip-path: polygon(50% 0, 0% 100%, 100% 100%);
transform: rotateY(calc(var(--i)*36deg));
background-image: url(./img/525.jpg);
transform-style: preserve-3d;
transform-origin: center center;
animation: hh 50s linear infinite alternate;
background-size: contain;
}
@keyframes hh {
10%{
background-image: url(./img/1.png);
}
20%{
background-image: url(./img/3.png);
}
30%{
background-image: url(./img/2.png);
}
40%{
background-image: url(./img/4.png);
}
50%{
background-image: url(./img/5.png);
}
60%{
background-image: url(./img/6.png);
}
70%{
background-image: url(./img/7.png);
}
80%{
background-image: url(./img/8.png);
}
90%{
background-image: url(./img/9.png);
}
}
#box{
width: 50vw;
height: 50vw;
display: flex;
justify-content: center;
align-items: center;
transform-style: preserve-3d;
position: relative;
perspective: 5000px;
perspective-origin: center center;
top: 50px;
animation: db 12s linear infinite;
}
@keyframes db {
0%{
transform: rotateY(0deg);
}
100%{
transform: rotateY(360deg);
}
}
html {
overflow: hidden;
}
#can {
filter: blur(2px);
z-index: -1;
}
#can2{
position: absolute;
z-index: -2;
}
#canvas{
position: absolute;
z-index: -3;
}
.bz{
width: 20px;
position: absolute;
height: 200px;
top: 520px;
transform: rotateY(calc(var(--i)*36deg));
background-image: url(./img/3.png);
background-size: contain;
}
/* #bg{
width: 100vw;
height: 100vh;
position: absolute;
z-index: 99;
background-image: url(./img/525.jpg);
background-size: 100% 100%;
} */
</style>
</head>
<body>
<div id="box">
<div v-for="(item, index) in 100" :key="index" class="act" :key="index" :style="'--i:'+index">{{index}}</div>
<div v-for="(item, index) in 100" :key="index" class="bz" :style="'--i:'+index"></div>
</div>
<canvas id="can2"></canvas>
<canvas id="can"></canvas>
<canvas id="canvas"></canvas>
<!-- <div id="bg"></div> -->
<script>
const vm = new Vue({
el: "#box",
})
/**@type{HTMLCanvasElement}*/
const can = document.getElementById("can");
const ctx = can.getContext("2d");
can.width = window.innerWidth;
can.height = window.innerHeight;
window.onresize = function () {
can.width = window.innerWidth;
can.height = window.innerHeight
}
let arr = [];
class Xue {
constructor() {
this.x = this.Random().x;
this.y = this.Random().y;
this.r = this.Random().r;
this.color = "white";
this.v = this.Random().v;
this._v = this.Random()._v;
arr.push(this)
};
Random() {
return {
x: Math.random() * can.width,
y: 0,
r: Math.random() * (4 - 1) + 1,
v: Math.random() * (5 - 0.54) + 0.54,
_v: (Math.random() * (1 + 1) - 1) * 1,
}
}
Path() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2, true);
ctx.fillStyle = this.color;
ctx.fill();
ctx.closePath();
}
run() {
this.x += this._v;
this.y += this.v;
}
newS() {
new Xue();
}
}
function runs(shu) {
for (let i = 0; i < shu; i++) {
new Xue();
}
setTimeout(() => {
for (let i = 0; i < arr.length; i++) {
arr[i].Path()
console.log(111);
}
}, 100)
}
runs(200);
function start() {
ctx.clearRect(0, 0, can.width, can.height)
for (let i = 0; i < arr.length; i++) {
arr[i].Path();
arr[i].run()
if (arr[i].y > can.height || arr[i].x > can.width || arr[i].x < 0) {
arr[i].newS()
arr.splice(i, 1);
}
}
// console.log(arr);
requestAnimationFrame(start);
}
start();
</script>
<!-- <script src="./JS/yanhua.js"></script> -->
<script src="./JS/yu.js"></script>
</body>
</html>
这一段的js代码在这儿喔!!!
var canvas = document.getElementById("canvas")
var ctx3 = canvas.getContext("2d")
canvas.width = window.innerWidth
canvas.height = window.innerHeight
var meteors = []
var allstar = 40
function init() {
for (var i = 0; i < allstar; i++) {
newmeteor()
}
}
function newmeteor(){
meteors.push({
lines: [{
x: parseInt(Math.random() * canvas.width),
y: parseInt(Math.random() * canvas.height * 0.4),
}],
life: parseInt(Math.random() * 100) + 100,
age: 0
})
}
function draw() {
ctx3.clearRect(0, 0, canvas.width, canvas.height)
for (var i = 0; i < meteors.length; i++) {
meteor = meteors[i]
lines = meteor.lines
for (var j = 0; j < lines.length; j++) {
ctx3.fillStyle = "rgba(255,255,255," + j / lines.length + ")"
ctx3.fillRect(lines[j].x, lines[j].y, 1, 1)
}
ctx3.fillStyle = "yellow"
var star = lines[lines.length-1]
ctx3.fillRect(star.x, star.y, 2, 2)
if (meteor.age <= meteor.life / 2) {
lines.push({
x: star.x+1 ,
y: star.y+0.3
})
}
else {
lines.shift()
}
meteor.age++
if (meteor.age >= meteor.life) {
meteors.splice(i, 1)
newmeteor()
}
}
}
init()
setInterval(draw, 1)
效果图如下:
希望能帮助到你喔 [滑稽][滑稽]