萤火虫的灵感来源于我玩的一个小游戏。小游戏里面有个活动叫“萤星漫舞”,使用道具的时候,会有萤火虫闪光的特效,特别好看。
萤火虫的记忆还停留在我的童年,乡间田野之间,夏日到来的夜晚,偶尔会和玩伴们一起去冒险,经常能遇到星星点点的萤火虫。长大后,繁华都市的华灯,虽然璀璨夺目,但是让我感觉遥远且冰冷。萤火微小,却照亮了我探索自然的路。
再次遇到萤火虫相关的场景,勾起我对童年的美好回忆,于是我决定复刻这个场景,来迎接夏日的到来。萤星漫舞的效果使用CSS3便能实现。
“望孟夏之短夜兮,何晦明之若岁?” --屈原《九章》
“孟夏之夜虽然短暂,但如遇萤星之光,可照前进之路。”--叶一一
为了增加趣味性,有些按钮激活状态下,会有光束游走效果,像老牌店铺的霓虹灯。
#button {
position: absolute;
left: 50%;
bottom: 15%;
width: 150px;
height: 40px;
line-height: 40px;
background: transparent;
margin-left: -75px;
text-align: center;
color: #fc91ab;
border: 2px solid #fc91ab;
cursor: pointer;
overflow: hidden;
display: block;
z-index: 99;
}
#button:hover {
background-color: #fc91ab;
color: #fff;
box-shadow: 0 0 25px #fc91ab;
border: none;
}
#button:hover i {
position: absolute;
}
#button:hover i:nth-child(odd) {
width: 100%;
height: 2px;
}
#button:hover i:nth-child(even) {
width: 2px;
height: 100%;
}
#button:hover i:nth-child(1) {
top: 0;
left: -100%;
background: linear-gradient(to right, transparent, #fff);
animation: moveligth1 1s linear infinite;
}
#button:hover i:nth-child(2) {
top: -100%;
right: 0;
background: linear-gradient(to bottom, transparent, #fff);
animation: moveligth2 1s linear infinite;
animation-delay: 0.25s;
}
#button:hover i:nth-child(3) {
bottom: 0;
right: -100%;
background: linear-gradient(to left, transparent, #fff);
animation: moveligth3 1s linear infinite;
animation-delay: 0.5s;
}
#button:hover i:nth-child(4) {
bottom: -100%;
left: 0;
background: linear-gradient(to top, transparent, #fff);
animation: moveligth4 1s linear infinite;
animation-delay: 0.75s;
}
@keyframes moveligth1 {
0% {
left: -100%;
}
50%,
100% {
left: 100%;
}
}
@keyframes moveligth2 {
0% {
top: -100%;
}
50%,
100% {
top: 100%;
}
}
@keyframes moveligth3 {
0% {
right: -100%;
}
50%,
100% {
right: 100%;
}
}
@keyframes moveligth4 {
0% {
bottom: -100%;
}
50%,
100% {
bottom: 100%;
}
}
<div id="button">
<i></i>
<i></i>
<i></i>
<i></i>
萤星漫舞
</div>
var light = document.getElementById('light');
var searchlight = document.getElementById('searchlight');
var aperture = document.getElementById('aperture');
var button = document.getElementById('button');
// 设置样式
function setStyle(str, flag) {
light.style.display = str;
searchlight.style.display = str;
aperture.style.display = str;
button.disabled = flag;
}
// 点击事件 开启动画效果
function lightShow() {
setStyle('block', true);
setTimeout(function () {
setStyle('none', false);
}, 3000);
}
button.onclick = lightShow;
手电筒效果包括屏幕和光束两部分
#searchlight {
position: absolute;
top: 407px;
left: 85px;
height: 45px;
border-radius: 5px;
border-bottom: 40px solid transparent;
border-left: 100px solid #d1da8b;
border-top: 40px solid transparent;
border-radius: 5px;
animation: searchlightchange 3s linear alternate infinite;
transform-origin: 100%;
transform: rotate(51deg);
z-index: 108;
display: none;
}
#searchlight::before {
content: '';
position: absolute;
border-radius: 50%;
width: 37px;
height: 125px;
background: #d1da8b;
left: -119px;
top: -40px;
transform: rotate3d(1, 0, 1, 0deg);
}
@keyframes searchlightchange {
0% {
opacity: 0.1;
}
50% {
opacity: 0.3;
}
100% {
opacity: 0.1;
}
}
#aperture {
position: absolute;
top: 461px;
left: 158px;
width: 54px;
height: 15px;
border-radius: 100%;
background: #fff;
transform: rotate3d(1, 0, 1, -57deg);
box-shadow: 1px 1px 20px #fff;
z-index: 109;
display: none;
}
<div id="searchlight"></div>
<div id="aperture"></div>
萤火虫发光效果仿照的星星闪烁效果,即明暗交替。将每个萤火虫容器的背景设置透明度从1到0.5即可。
#light {
position: absolute;
top: 376px;
left: 94px;
width: 125px;
height: 100px;
z-index: 119;
background: none;
display: none;
}
#light .spot {
border-radius: 50%;
background: #c3cb78;
position: absolute;
box-shadow: 1px 1px 20px #c3cb78;
animation: spotchange 1.5s linear alternate infinite;
}
@keyframes spotchange {
0% {
opacity: 1;
}
50% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
#light .spot::before {
content: '';
position: absolute;
border-radius: 50%;
background: rgba(195, 203, 120, 0.7);
box-shadow: 1px 1px 10px #c3cb78;
left: -1px;
top: -1px;
}
#light .spot-1 {
top: 10px;
left: 10px;
width: 5px;
height: 5px;
}
#light .spot-1::before {
width: 7px;
height: 7px;
}
#light .spot-2 {
top: 35px;
left: -5px;
width: 3px;
height: 3px;
}
#light .spot-2::before {
width: 5px;
height: 5px;
}
#light .spot-3 {
top: 35px;
left: 30px;
width: 3px;
height: 3px;
}
#light .spot-3::before {
width: 5px;
height: 5px;
}
#light .spot-4 {
top: 22px;
left: 57px;
width: 5px;
height: 5px;
}
#light .spot-4::before {
width: 7px;
height: 7px;
}
#light .spot-5 {
top: 15px;
left: 90px;
width: 3px;
height: 3px;
}
#light .spot-5::before {
width: 5px;
height: 5px;
}
#light .spot-6 {
top: 75px;
left: 50px;
width: 5px;
height: 5px;
}
#light .spot-6::before {
width: 7px;
height: 7px;
}
#light .spot-7 {
top: 54px;
left: 74px;
width: 3px;
height: 3px;
}
#light .spot-7::before {
width: 5px;
height: 5px;
}
#light .spot-8 {
top: -5px;
left: 44px;
width: 3px;
height: 3px;
}
#light .spot-8::before {
width: 5px;
height: 5px;
}
#light .spot-9 {
top: 80px;
left: 75px;
width: 3px;
height: 3px;
}
#light .spot-9::before {
width: 5px;
height: 5px;
}
#light .spot-10 {
top: 60px;
left: 35px;
width: 3px;
height: 3px;
}
#light .spot-10::before {
width: 5px;
height: 5px;
}
<ul id="light">
<li class="spot spot-1"></li>
<li class="spot spot-2"></li>
<li class="spot spot-3"></li>
<li class="spot spot-4"></li>
<li class="spot spot-5"></li>
<li class="spot spot-6"></li>
<li class="spot spot-7"></li>
<li class="spot spot-8"></li>
<li class="spot spot-9"></li>
<li class="spot spot-10"></li>
</ul>
关于萤火虫的回忆就告一段落了。其实「童年」和「夏天」这两个标签,能碰撞出很多美好回忆。莲蓬、溪流、捉虾、西瓜、知了、蛙叫、萤火虫等等,离自然越近的时候,夏天越发有趣。
所以,我比较喜欢偏生活类的游戏,算是与生俱来的种田情怀吧。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。