<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小太阳我爱你</title>
<link rel="stylesheet" href="./love.css">
</head>
<body>
<div class="container" onselectstart="return false;" unselectable="on" style="-moz-user-select: none;">
<div class="body_left">
<img src="./images/biubiubiu.gif" alt="" ondragstart='return false;'>
<div class="border" style="margin-left: 30px;color: rgb(221, 186, 186);">
<h2>you are my love</h2>
</div>
</div>
<div class="body_center love">
<div class="block">
<div class="div1"></div>
<div class="div2"></div>
<div class="div3"></div>
<div class="div4"></div>
</div>
</div>
<div class="footer">
<div class="border">
<div class="border-top"></div>
<div class="border-bottom"></div>
</div>
<!-- 版本号、日期、著名 -->
<div class="copyright">
<div id="version"><span></span> Cynthia</div>
<div id="createTime"><span>Time:</span> 2023/9/8</div>
<div id="author"><span>© </span>yaoyao</div>
<div id="autio">
<audio controls>
<source src="horse.ogg" type="audio/ogg">
</audio>
</div>
</div>
</div>
</div>
<script src="./love.js"></script>
<script>
let blocks = document.getElementsByClassName("block")
let block = blocks[0]
let love = document.getElementsByClassName("love")[0] // 定义love为下标为0的元素
let timer = null//定时器
let index = 0//记录拼接爱心的动画步骤//用于克隆方块
let clone_block;
//1.移动方块的[自身中心] 到[爱心中心]
block.style.top = "50%";
block.style.left = "50%";
block.style.margin = "-20px 0 0 -20px";
const block_left = parseFloat(window.getComputedStyle(block, null).left.slice(0, -2))
const block_top = parseFloat(window.getComputedStyle(block, null).top.slice(0, -2))
function Next() {
if (++index >= 24) {
clearInterval(timer);
Rise();
return
}
block.style.visibility = "visible"//升空动画前允许可见
block.style.left = block_left + 40 * offset_pitn["block" + index][0] + "px"
block.style.top = block_top - 40 * offset_pitn["block" + index][1] + "px"
for (let i = 0; i < block.children.length; i++) {//编号便于调试
block.children[i].style.left = blk_pitn["block" + index][i][0] * -40 + "px"
block.children[i].style.top = blk_pitn["block" + index][i][1] * -40 + "px"
}
clone_block = block.cloneNode(true);
love.appendChild(clone_block);
if (love.children.length >= 24) {
blocks[blocks.length - 1].children[2].style.display = "none";//去掉多余的小方块
block.style.display = "none";
}
}
function Rise() {
let timer2 = null
let distance = 0
const target = 120
let speed = 2
let love_top = parseFloat(window.getComputedStyle(love, null).top.slice(0, -2));
timer2 = setInterval(() => {
distance += speed
if (distance >= target) {
clearInterval(timer2)
}
love.style.top = (love_top - distance) + "px"
}, 22)
}
window.onload = () => {
setTimeout(() => {
timer = setInterval(() => {
Next()
}, 300)
}, 3000)
}
</script>
</body>
</html>
css
* {
margin: 0;
padding: 0;
border: 0;
}
html,
body {
width: 100%;
height: 100%;
}
body {
overflow: hidden;
}
.container {
width: 100%;
height: 100%;
position: relative;
}
.body_left {
width: 300px;
height: 300px;
position: absolute;
left: 0;
bottom: 110px;
Z-index: 98;
}
.container .love {
width: 520px;
height: 440px;
position: absolute;
left: 50%;
top: 50%;
margin: -260px 0 0 -220px;
}
.love .block {
right: 0;
position: absolute;
visibility: hidden;
}
.love .block div {
width: 40px;
height: 40px;
position: absolute;
background: url("../images/heart.png") no-repeat;
background-size: contain;
box-sizing: border-box;
}
@keyframes border {
0% {
width: 0;
}
/* 5% {
width: 5%
} */
/* 10% {
width: 10%;
} */
/* 15% {
width: 15%;
} */
20% {
width: 20%;
}
/* 25% {
width: 25%;
} */
/* 30% {
width: 30%;
} */
/* 35% {
width: 35%;
} */
40% {
width: 40%;
}
/* 45% {
width: 45%;
} */
/* 50% {
width: 50%;
} */
/* 55% {
width: 55%;
} */
60% {
width: 60%;
}
/* 65% {
width: 65%;
} */
/* 70% {
width: 70%;
} */
/* 75% {
width: 75%;
} */
80% {
width: 80%;
}
/* 85% {
width: 85%;
} */
/* 90% {
width: 90%;
} */
/* 95% {
width: 95%;
} */
100% {
width: 100%;
}
}
.footer {
bottom: -900px;
position: relative;
Z-index: 99;
}
.footer .border .border-top {
border-top: 3px solid black;
transform-origin: left center;
-webkit-animation: border 312 linear;
-o-animation: border 4s linear;
animation: border 4s linear;
animation-fill-mode: both;
}
footer .border .border-bottom {
float: right;
border-top: 3px solid red;
transform-origin: right center;
-webkit-animation: border 2s linear 4s;
-o-animation: border 2s linear 4s;
animation: border 2s linear 4s;
animation-fill-mode: both;
}
footer .copyright {
width: 100%;
height: 30px;
position: absolute;
bottom: -30px;
text-align: center;
}
.copyright div {
width: 30%;
line-height: 30px;
display: inline-block;
}
.copyright div span {
color: dimgray
}
js
const blk_pitn = {
block1: [[0, 1], [0, 0], [-1, 0], [-1, -1]],
block2: [[0, 1], [0, 0], [-1, 0], [0, -1]],
block3: [[-1, 1], [0, 0], [-1, 0], [-1, -1]],
block4: [[0, 1], [0, 0], [-1, 0], [-1, -1]],
block5: [[-1, 1], [0, 0], [-1, 0], [0, -1]],
block6: [[0, -1], [0, 0], [-1, 0], [1, -1]],
block7: [[-1, -1], [0, 0], [-1, 0], [1, 0]],
block8: [[-1, 1], [0, 0], [-1, 0], [-1, -1]],
block9: [[0, -1], [0, 0], [-1, 0], [1, 0]],
block10: [[-1, 1], [0, 0], [-1, 0], [1, 0]],
block11: [[2, 0], [0, 0], [-1, 0], [1, 0]],
block12: [[0, 1], [0, 0], [-1, 0], [0, -1]],
block13: [[0, 1], [0, 0], [-1, 0], [-1, -1]],
block14: [[1, 1], [0, 0], [-1, 0], [1, 0]],
block15: [[1, -1], [0, 0], [-1, 0], [1, 0]],
block16: [[-1, -1], [0, 0], [-1, 0], [1, 0]],
block17: [[0, 1], [0, 0], [-1, 0], [0, -1]],
block18: [[0, 1], [0, 0], [-1, 0], [-1, -1]],
block19: [[0, -1], [0, 0], [-1, 0], [1, 0]],
block20: [[1, -1], [0, 0], [-1, 0], [1, 0]],
block21: [[0, 1], [0, 0], [-1, 0], [-1, -1]],
block22: [[1, 1], [0, 0], [-1, 0], [1, 0]],
block23: [[0, 2], [0, 0], [0, -1], [0, 1]]
}
const offset_pitn = {
block1: [5, 3],
block2: [5, 1],
block3: [3, 4],
block4: [3, 2],
block5: [3, -1],
block6: [2, 5],
block7: [2, 1],
block8: [1, -1],
block9: [1, -3],
block10: [1, 2],
block11: [0, 3],
block12: [0, 0],
block13: [-1, -4],
block14: [0, -2],
block15: [-2, 4],
block16: [-2, 2],
block17: [-2, 0],
block18: [-3, -2],
block19: [-4, 0],
block20: [-3, 5],
block21: [-5, 3],
block22: [-4, 1],
block23: [-6, 1],
}