
悬停代码小瀑布按钮
适用于科技感的网站中,此按钮有助于增加网站的科技感效果。
核心代码部分,简要说明了写法思路;完整代码在最后,可直接复制到本地运行。
知识点:
1️⃣ transition 过渡属性
2️⃣ animation 动画属性
3️⃣ :nth-child(n) 和 :hover 选择器
4️⃣ -- 自定义属性(css变量)以及 var(...) 引用自定义属性值函数和 calc(...) 计算属性值函数
思路:基于上一例代码瀑布加载动画,实现鼠标悬浮在按钮上方时,显示出其代码瀑布动画。
核心代码
html 代码
<div class="btn-box80"> <button class="btn80">HOVER</button><div class="loading80"><p class="p80">4rs<span class="i80-1">b</span>h<span class="i80">k</span>r</p><p class="p80">_7u<span class="i80">i</span>90<span class="i80">@</span>v</p><p class="p80">_7,=<span class="i80-1">j</span>ud<span class="i80">i</span>y</p><p class="p80">d8<span class="i80-1">%</span>rg</p><p class="p80"><span class="i80">d</span>oopd<span class="i80-1">e</span>g</p><p class="p80">c4*<span class="i80-1">h</span>ld</p><p class="p80">u<span class="i80">g</span>_^43<span class="i80">2</span>iu</p></div></div>
按钮开关主体代码结构。
CSS部分代码
.btn-box80{width:124px;height:46px;position: relative;display: flex;justify-content: center;align-items: center;cursor: pointer;--color-f:#43ff85;--color-s:#6c72fe;--color-t:#f7e543;}.btn80{width:124px;height:46px;font-size:20px;font-weight: bold;letter-spacing:4px;outline: none;background-color: transparent;border:2px solid var(--color-f);color:var(--color-f);position: absolute;padding:0;cursor: pointer;z-index:1;transition: all 0.24s linear;}.loading80{width:124px;height:46px;font-size:24px;font-weight: bold;letter-spacing:4px;background-color: transparent;position: absolute;left:-2px;overflow: hidden;cursor: pointer;z-index:0;opacity:0;transition: opacity 0.24s linear;}.p80{cursor: pointer;writing-mode: vertical-rl;letter-spacing:3px;font-size:12px;line-height:1;margin:0;padding:0;position: absolute;color:var(--color-f);--left:3px;--delay:0.1s;animation: eff80 0.6s linear infinite;}.i80{color:var(--color-s);}.i80-1{color:var(--color-t);}.p80:nth-child(1){left:var(--left);}.p80:nth-child(2){left:calc(var(--left)+18px);animation-delay:var(--delay);}.p80:nth-child(3){left:calc(var(--left)+18px*2);animation-delay:calc(var(--delay)*2);}.p80:nth-child(4){left:calc(var(--left)+18px*3);}.p80:nth-child(5){left:calc(var(--left)+18px*4);animation-delay:calc(var(--delay)*4);}.p80:nth-child(6){left:calc(var(--left)+18px*5);animation-delay:calc(var(--delay)*3);}.p80:nth-child(7){left:calc(var(--left)+18px*6);}@keyframes eff80{0%{transform:translateY(-40%);}100%{transform:translateY(140%);}}.btn-box80:hover.btn80{text-shadow:02px0var(--color-s);box-shadow:2px2px0var(--color-s),-2px-2px0var(--color-t);}.btn-box80:hover.loading80{opacity:1;background-color:#000000;}
这里在上一例的基础上,增加了按钮样式,利用 :hover 来显示隐藏代码瀑布动画。
完整代码
html页面
<!DOCTYPE html><html lang="zh"><head><meta charset="utf-8">
<title>悬停代码小瀑布按钮</title>
<style>
.app{width:100%;height:100vh;background-color:#ffffff;position: relative;display: flex;justify-content: center;align-items: center;}.btn-box80{width:124px;height:46px;position: relative;display: flex;justify-content: center;align-items: center;cursor: pointer;--color-f:#43ff85;--color-s:#6c72fe;--color-t:#f7e543;}.btn80{width:124px;height:46px;font-size:20px;font-weight: bold;letter-spacing:4px;outline: none;background-color: transparent;border:2px solid var(--color-f);color:var(--color-f);position: absolute;padding:0;cursor: pointer;z-index:1;transition: all 0.24s linear;}.loading80{width:124px;height:46px;font-size:24px;font-weight: bold;letter-spacing:4px;background-color: transparent;position: absolute;left:-2px;overflow: hidden;cursor: pointer;z-index:0;opacity:0;transition: opacity 0.24s linear;}.p80{cursor: pointer;writing-mode: vertical-rl;letter-spacing:3px;font-size:12px;line-height:1;margin:0;padding:0;position: absolute;color:var(--color-f);--left:3px;--delay:0.1s;animation: eff80 0.6s linear infinite;}.i80{color:var(--color-s);}.i80-1{color:var(--color-t);}.p80:nth-child(1){left:var(--left);}.p80:nth-child(2){left:calc(var(--left)+18px);animation-delay:var(--delay);}.p80:nth-child(3){left:calc(var(--left)+18px*2);animation-delay:calc(var(--delay)*2);}.p80:nth-child(4){left:calc(var(--left)+18px*3);}.p80:nth-child(5){left:calc(var(--left)+18px*4);animation-delay:calc(var(--delay)*4);}.p80:nth-child(6){left:calc(var(--left)+18px*5);animation-delay:calc(var(--delay)*3);}.p80:nth-child(7){left:calc(var(--left)+18px*6);}@keyframes eff80{0%{transform:translateY(-40%);}100%{transform:translateY(140%);}}.btn-box80:hover.btn80{text-shadow:02px0var(--color-s);box-shadow:2px2px0var(--color-s),-2px-2px0var(--color-t);}.btn-box80:hover.loading80{opacity:1;background-color:#000000;}
</style>
</head>
<body><div class="app"><div class="btn-box80"><button class="btn80">HOVER</button><div class="loading80"><p class="p80">4rs<span class="i80-1">b</span>h<span class="i80">k</span>r</p><p class="p80">_7u<span class="i80">i</span>90<span class="i80">@</span>v</p><p class="p80">_7,=<span class="i80-1">j</span>ud<span class="i80">i</span>y</p><p class="p80">d8<span class="i80-1">%</span>rg</p><p class="p80"><span class="i80">d</span>oopd<span class="i80-1">e</span>g</p><p class="p80">c4*<span class="i80-1">h</span>ld</p><p class="p80">u<span class="i80">g</span>_^43<span class="i80">2</span>iu</p></div></div></div></body></html>
以上就是所有代码,以及简单的思路,希望对你有一些帮助或者启发。
[超站]友情链接:
四季很好,只要有你,文娱排行榜:https://www.yaopaiming.com/
关注数据与安全,洞悉企业级服务市场:https://www.ijiandao.com/

随时掌握互联网精彩
- 1 把最好的精神食粮奉献给人民 7990751
- 2 DeepSeek评中国最宜居城市 7966428
- 3 网友呼吁《难哄》下架 7852197
- 4 手机国补满月 持续点燃消费热潮 7773169
- 5 民警建议家里不要安装摄像头 7632131
- 6 《哪吒2》票房破128亿 7579995
- 7 #平台为骑手缴社保外卖员们怎么看# 7430158
- 8 制作人员做无量仙翁时以为是好人 7326592
- 9 戚薇李承铉 离婚是另外一个节目 7236935
- 10 奶奶每天玩手机到凌晨近视2300度 7134032