摘要:介绍原文链接感謝大佬的前端每日实战效果预览浏览源代码地址代码解读首先是完成结构常规样式初始化天上的星星原文中星星是固定位置并且不会闪烁的而这里我们将会改变这一状态而且为了避免重复手动给星星固定位置及大小所以采用了库来减少麻烦首先将改
介绍
</>复制代码
原文链接感謝 comehope 大佬的 [前端每日实战]
效果预览
</>复制代码
github.io 浏览
源代码地址
https://github.com/shanyuhai1...
代码解读 1. 首先是完成 html 结构</>复制代码
常规样式初始化
</>复制代码
* {
margin: 0;
padding: 0;
}
body {
margin: 0;
padding: 0 0.5vw;
height: 100vh;
background-color: #333;
overflow: hidden;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
2. 天上的星星
原文中星星是固定位置并且不会闪烁的
而这里我们将会改变这一状态, 而且为了避免重复手动给星星固定位置及大小, 所以采用了 d3 库来减少麻烦
</>复制代码
首先将 .stars 改为 grid 布局
使用 span 标签 作为星星
因为星星要分时间闪烁所以随机一个 --delay 参数
</>复制代码
// index.js
const COLUMNS = 15;
d3.select(".stars")
.style("--columns", COLUMNS)
.selectAll("span")
.data(d3.range(COLUMNS * COLUMNS))
.enter()
.append("span")
.style("--delay", () => Math.random() * 20);
先给出大概的范围, 查看下边界
</>复制代码
.stars {
width: 99vw;
height: 70vh;
position: absolute;
display: grid;
grid-template-columns: repeat(var(--columns), 1fr);
border: 1px solid;
}
.stars span {
width: 0.6vw;
height: 0.6vw;
color: whitesmoke;
background-color: currentColor;
}
星星现在只是一个个正方形, 再给正方形添加上旋转闪现的动画即可
</>复制代码
.stars span {
transform: scale(0);
animation: spin 20s linear infinite;
animation-delay: calc(var(--delay) * 1s);
}
@keyframes spin {
0% {
transform: rotate(0deg) scale(1);
}
5%,
15% {
transform: rotate(90deg) scale(0);
background: goldenrod;
}
17.5% {
transform: rotate(180deg) scale(1);
background-color: currentColor;
}
20%,
100% {
transform: rotate(90deg) scale(0);
}
}
3. 添加火堆
首先是修改 DOM
</>复制代码
使火堆居中, 利用媒体查询改变一下在手机端偏小的问题
</>复制代码
.fires {
position: relative;
border: 1px solid;
}
@media screen and (min-width: 451px) {
.fires {
width: 15vw;
height: 15vw;
margin-top: -7vw;
}
}
@media screen and (max-width: 450px) {
.fires {
width: 18vh;
height: 18vh;
margin-top: -5vw;
}
}
接着完成火焰效果, 在父级添加可用的 color , border-radius 变量
</>复制代码
.fires {
position: relative;
display: flex;
align-items: center;
justify-content: center;
border: 1px solid;
--color-one: #D92B29;
--color-two: #F5732A;
--color-three: #F2B338;
--color-four: #F5D549;
--shape-one: 79% 21% 64% 36% / 43% 61% 39% 57%;
--shape-two: 23% 77% 66% 34% / 57% 72% 28% 43%;
--shape-three: 78% 22% 63% 37% / 39% 27% 73% 61%;
--shape-four: 35% 65% 78% 22% / 54% 50% 50% 46%;
}
@media screen and (min-width: 451px) {
.fires__flame {
width: 6vw;
}
.fires__flame:nth-of-type(1) {
height: 15vw;
}
.fires__flame:nth-of-type(2) {
height: 12vw;
transform: translate(2.25vw, 1.2vw) rotate(30deg);
}
.fires__flame:nth-of-type(3) {
height: 13.5vw;
transform: translate(-2.25vw, 1.2vw) rotate(-30deg);
}
.fires__flame:nth-of-type(4) {
height: 10.5vw;
}
}
@media screen and (max-width: 450px) {
.fires__flame {
width: 7.2vh;
}
.fires__flame:nth-of-type(1) {
height: 18vh;
}
.fires__flame:nth-of-type(2) {
height: 14.4vh;
transform: translate(2.7vh, 1.44vh) rotate(30deg);
}
.fires__flame:nth-of-type(3) {
height: 16.2vh;
transform: translate(-2.7vh, 1.44vh) rotate(-30deg);
}
.fires__flame:nth-of-type(4) {
height: 12.6vh;
}
}
.fires__flame {
position: absolute;
background-color: var(--color-one);
border-radius: var(--shape-one);
z-index: 0;
animation-name: fire;
animation-duration: 1.5s;
animation-iteration-count: infinite;
transition: ease 0.4s;
}
.fires__flame:nth-of-type(2) {
border-radius: var(--shape-two);
background-color: var(--color-two);
opacity: 0.9;
z-index: 2;
animation-delay: 0.2s;
}
.fires__flame:nth-of-type(3) {
border-radius: var(--shape-three);
background-color: var(--color-three);
opacity: 0.8;
z-index: 1;
animation-delay: 0.4s;
}
.fires__flame:nth-of-type(4) {
border-radius: var(--shape-four);
background-color: var(--color-four);
opacity: 0.8;
z-index: 1;
animation-delay: 0.6s;
}
当然别忘了火焰的动画效果
</>复制代码
@keyframes fire {
0% {
border-radius: var(--shape-one);
background-color: var(--color-one);
}
25% {
border-radius: var(--shape-two);
background-color: var(--color-two);
}
50% {
border-radius: var(--shape-three);
background-color: var(--color-three);
}
75% {
border-radius: var(--shape-four);
background-color: var(--color-four);
}
100% {
border-radius: var(--shape-one);
background-color: var(--color-one);
}
}
再添加木柴
</>复制代码
@media screen and (min-width: 451px) {
.fires__stick {
border-radius: 1.5vw;
width: 3vw;
height: 13.5vw;
bottom: -7.5vw;
}
}
@media screen and (max-width: 450px) {
.fires__stick {
border-radius: 1.8vh;
width: 3.6vh;
height: 16.2vh;
bottom: -9vh;
}
}
.fires__stick {
background-color: #5a3600;
position: absolute;
z-index: 2;
transform:rotate(-70deg);
}
.fires__stick:last-of-type {
transform:rotate(70deg);
background-color: #4e2f01;
}
4. 最后
最后记得把之前确认位置及大小的 border 边框删除即可
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/117129.html
摘要:前言说到对图片进行处理,我们经常会想到这类的图像处理工具。或者是的时候,对图片的对比度,阴影进行处理。过滤器通常被用于调整图片,背景和边界的渲染。最后,安利我们的公众号前端指南。 前言 说到对图片进行处理,我们经常会想到PhotoShop这类的图像处理工具。作为前端开发者,我们经常会需要处理一些特效,例如根据不同的状态,让图标显示不同的颜色。或者是hover的时候,对图片的对比度,阴影...
摘要:前言说到对图片进行处理,我们经常会想到这类的图像处理工具。或者是的时候,对图片的对比度,阴影进行处理。过滤器通常被用于调整图片,背景和边界的渲染。最后,安利我们的公众号前端指南。 前言 说到对图片进行处理,我们经常会想到PhotoShop这类的图像处理工具。作为前端开发者,我们经常会需要处理一些特效,例如根据不同的状态,让图标显示不同的颜色。或者是hover的时候,对图片的对比度,阴影...
摘要:本文首发于个人博客项目源码,欢迎,说不定哪天脱单了就能用到了写在前面自从用邮箱注册了很多账号后,便会收到诸如以下类似的邮件刚开始还以为是一张图片,后来仔细一看不是图片呀,好像还是呀,于是好奇宝宝我一下,查阅多篇资料后总结出怎么用前端知识和做 本文首发于个人博客:VinceBlog 项目源码:NodeMail,欢迎star,说不定哪天脱单了就能用到了 写在前面 自从用邮箱注册了很多账号后...
阅读 1745·2021-10-13 09:39
阅读 2168·2021-09-07 10:20
阅读 2760·2019-08-30 15:56
阅读 3029·2019-08-30 15:56
阅读 999·2019-08-30 15:55
阅读 740·2019-08-30 15:46
阅读 3559·2019-08-30 15:44
阅读 2632·2019-08-30 11:15