当前位置:网站首页>七夕节,我用代码制作了表白信封
七夕节,我用代码制作了表白信封
2022-08-04 04:00:00 【王子周棋洛】
大家好,我是小周,明天就是七夕了,这么浪漫的节日,自然少不了我这个浪漫博主,本次为大家贡献表白信封的制作,其他的就看缘分啦,哈哈,最后会放上资源包,需要的小伙伴自取就可以了,999
一、画信封
https://excalidraw.com/
使用上面的画图工具,手绘信封,可自己发挥,工具上手简单也很不错
图1:未打开的信封

图2:快要打开的信封

图3:打开的信封

二、结构搭建
这是整个项目的结构,其中都标注了是干嘛的,清晰明了

三、HTML结构
很简单,使用一个大盒子包裹所有内容,包括图片,文字
<!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>
<link rel="shortcut icon" href="./icon/icon.png" type="image/x-icon">
<link rel="stylesheet" href="./css/index.css">
</head>
<body>
<div class="con">
<img src="./images/1.png" class="close" draggable="false">
<img src="./images/花.png" class="rose" draggable="false">
<h1>写给亲爱的郁苗小姐</h1>
<span>2022-8-4</span>
</div>
<audio src="./audio/click.mp3" class="clickMusic"></audio>
<audio src="./audio/ADG - 我 去 宇 宙 偷 星 星,放 在 夜 里 等 你*.mp3" class="bgMusic"></audio>
<script src="./js/main.js"></script>
</body>
</html>

四、CSS美化
关键注释已经写在代码中,使用了定义con相对于body定位,con内元素相对于con定位,不会乱,同时使用flex布局减少居中相关代码
/* 清除默认样式 */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 给body相对定位,让con以body为标准进行定位 */
body {
position: relative;
/* 设置最小高度为一整个视口的高度 */
min-height: 100vh;
}
/* 使用绝对定位,相对于body定位,居中 同时开启 flex布局,默认x轴为主轴,使用 justify-content: center;即x轴居中 */
.con {
position: absolute;
bottom: 150px;
width: 500px;
left: 50%;
transform: translateX(-50%);
display: flex;
justify-content: center;
}
.con .close {
position: absolute;
bottom: 0px;
width: 100%;
}
.con .rose {
position: absolute;
bottom: 70px;
width: 50px;
height: 50px;
/* 玫瑰是要点的,设置鼠标样式为小手 */
cursor: pointer;
}
.con h1 {
position: absolute;
bottom: 170px;
font-size: 18px;
color: #444;
}
.con span {
position: absolute;
bottom: 140px;
font-size: 14px;
color: #666;
}
/* 清除audio可能的占位问题 */
audio {
width: 0;
height: 0;
}
以下是简单美化后的效果:

五、JS注入灵魂
js也不难,获取节点,操作节点,使用定时器的时间差来模仿定格动画,达到开信封的效果,是不是很棒呢?注释已经写好了,如果你的基础差,看着注释也能明白哦
// 获取闭合信封的图片节点
let img1 = document.querySelector(".close");
// 获取h1和span文字节点
let h1 = document.querySelector("h1");
let span = document.querySelector("span");
// 获取点击音效
let clickMusic = document.querySelector(".clickMusic");
// 获取背景音乐
let bgMusic = document.querySelector(".bgMusic");
// 获取玫瑰,后面添加点击事件
let rose = document.querySelector(".rose");
// 添加点击事件
rose.addEventListener("click", function () {
// 先隐藏h1和span
h1.style.display = "none";
span.style.display = "none";
setTimeout(function () {
// 播放拆信封的音效
clickMusic.play();
// 200毫秒后切换信封为第二张
img1.src = "./images/2.png";
}, 200);
setTimeout(function () {
// 800毫秒后切换信封为第三张
img1.src = "./images/3.png";
// 播放背景音乐
bgMusic.play();
}, 800);
})
六、媒体查询,兼容移动端,拿捏
使用简单媒体查询,处理一下不同像素下的样式,小伙伴可以根据自己情况优化,我这里提供一下思路。
/* 媒体查询,简单兼容手机端,起飞 */
@media screen and (max-width: 540px) {
.con {
width: 100vw;
}
.con .rose {
bottom: 60px;
}
.con h1 {
bottom: 150px;
}
.con span {
bottom: 120px;
}
}
七、发送,直接恋爱
最后希望大家不要为了谈恋爱而谈恋爱️,在没有遇到真心喜欢的她他之前,充实自己,对自己好点,加油学技术,如果觉得博主说的不错,记得点赞支持博主呀,我是小周,期待你的关注!
八、源码下载
https://wwb.lanzouj.com/iJ7gH08yaw1g

边栏推荐
- Senior PHP development case (1) : use MYSQL statement across the table query cannot export all records of the solution
- 2 Gigabit Optical + 6 Gigabit Electric Rail Type Managed Industrial Ethernet Switch Supports X-Ring Redundant Ring One-key Ring Switch
- 八年软件测试工程师带你了解-测试岗进阶之路
- 千兆2光8电管理型工业以太网交换机WEB管理X-Ring一键环网交换机
- 系统设计.秒杀系统
- Metaverse "Drummer" Unity: Crazy expansion, suspense still exists
- 嵌入式数据库开发编程MySQL(全)
- SQL query String field less than 10 how to check
- 移动端响应式适配的方法
- 初识Numpy
猜你喜欢

2022杭电多校联赛第五场 题解

函数,递归以及dom简单操作

一文详解DHCP原理及配置

Postgresql源码(66)insert on conflict语法介绍与内核执行流程解析

汇编语言之栈
The general SQL injection flow (sample attached)

KingbaseES数据库启动失败,报“内存段超过可用内存”

拿捏JVM性能优化(自己笔记版本)
![[Medical Insurance Science] To maintain the safety of medical insurance funds, we can do this](/img/d0/6ac51d0d51c907ed0e1578e038fffd.jpg)
[Medical Insurance Science] To maintain the safety of medical insurance funds, we can do this

数据安全峰会2022 | 美创DSM获颁“数据安全产品能力验证计划”评测证书
随机推荐
tkmapper的crud示例:
DIY电工维修如何拆卸和安装开关面板插座
Mockito单元测试
帮助企业实现数字化转型成功的八项指导原则
【项目实现】Boost搜索引擎
类如何只能静态分配和只能动态分配
6-port full Gigabit Layer 2 network managed industrial Ethernet switch Gigabit 2 optical 4 electrical fiber self-healing ERPS ring network switch
Oracle与Postgresql在PLSQL内事务回滚的重大差异
Stop behind.
怎么把elastic中的异常登录ip和日志自动导出或抓取到数据库中?
LeetCode每日一题(2285. Maximum Total Importance of Roads)
【观察】超聚变:首提“算网九阶”评估模型,共建开放繁荣的算力网络
元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存
数据安全峰会2022 | 美创DSM获颁“数据安全产品能力验证计划”评测证书
高效IO模型
new Date converts strings into date formats Compatible with IE, how ie8 converts strings into date formats through new Date, how to replace strings in js, and explain the replace() method in detail
new Date将字符串转化成日期格式 兼容IE,ie8如何通过new Date将字符串转化成日期格式,js中如何进行字符串替换, replace() 方法详解
MySQL query optimization and tuning
基本表单验证流程
Innovation and Integration | Huaqiu Empowerment Helps OpenHarmony Ecological Hardware Development and Landing