子比美化 – 为网站添加一个动态灵动岛

906 字
5 分钟
子比美化 – 为网站添加一个动态灵动岛

效果演示#

实现方法#

1.将以下代码添加到自定义 CSS

[hidecontent type=“reply”]

/* 动态灵动岛美化样式代码*/
.dynamic-island {
position: fixed;
top: 80px;
left: 50%;
transform: translateX(-50%) scale(0);
transform-origin: center;
width: auto; /* 自动宽度 */
max-width: 80%; /* 最大宽度限制 */
height: 40px;
background-color: #000;
border-radius: 25px;
color: white;
display: flex;
align-items: center;
justify-content: space-between;
transition: transform 0.4s ease-in-out, height 0.6s ease-in-out, border-radius 0.6s ease-in-out, box-shadow 0.5s ease-in-out, opacity 0.5s ease-in-out;
overflow: visible;
z-index: 1000;
padding-left: 35px;
padding-right: 20px;
opacity: 0;
box-shadow: 0 0px 10px rgba(0, 0, 0, 0.45);
flex: 1; /* 使宽度自动扩展 */
white-space: nowrap; /* 防止文字换行 */
}
.dynamic-island.active {
transform: translateX(-50%) scale(1);
opacity: 1;
}
.dynamic-island.inactive {
transform: translateX(-50%) scale(0);
opacity: 0;
}
.island-content {
opacity: 0;
transition: opacity 0.9s ease-in-out, filter 0.8s ease-in-out;
font-weight: bold;
flex-grow: 1;
text-align: left; /* 文字左对齐 */
margin-left: 10px; /* 与图片留出空间 */
overflow: hidden; /* 防止溢出 */
text-overflow: ellipsis; /* 溢出显示省略号 */
}
.dynamic-island.active .island-content {
opacity: 1;
}
.dynamic-island img {
position: absolute;
left: 5px; /* 调整图片位置 */
width: 20px;
height: 20px;
object-fit: cover;
transition: height 0.8s ease-in-out, width 0.8s ease-in-out, filter 0.8s ease-in-out;
}
.dynamic-island:hover {
height: 60px;
border-radius: 50px;
}
.dynamic-island:hover img {
width: 30px;
height: 30px;
}
.bars {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 3px;
min-width: 40px; /* 最小宽度限制 */
}
.bar {
width: 2px;
height: 13px;
background-color: green;
animation: bounce 1s infinite ease-in-out;
animation-direction: alternate;
}
.bar:nth-child(1) {
animation-duration: 1s;
}
.bar:nth-child(2) {
animation-duration: 0.9s;
}
.bar:nth-child(3) {
animation-duration: 0.8s;
}
.bar:nth-child(4) {
animation-duration: 0.7s;
}
.bar:nth-child(5) {
animation-duration: 0.6s;
}
.bar:nth-child(6) {
animation-duration: 0.9s;
}
.bar:nth-child(7) {
animation-duration: 0.7s;
}
@keyframes bounce {
0% {
transform: scaleY(0.3);
background-color: green;
}
50% {
transform: scaleY(1);
background-color: orange;
}
100% {
transform: scaleY(0.3);
background-color: green;
}
}
/* 动态灵动岛美化样式代码 结束*/

[/hidecontent]

2.将以下代码添加到自定义头部 HTML

[hidecontent type=“reply”]

<!-- 动态灵动岛美化样式代码 开始 !-->
<div class="dynamic-island inactive" id="dynamicIsland" style="opacity: 0;">
<img src="https://img.alicdn.com/imgextra/i1/2210123621994/O1CN01lajerM1QbIl9aoHcJ_!!2210123621994.png" alt="通知图标" width="30" height="30">
<div class="island-content">
<div class="bars" style="line-height: 50px; margin: 0;">
<p style="line-height: 50px; margin: 0; font-size: 12px; padding-right: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;"> 欢迎访问站长论坛</p>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
</div>
</div>
<!-- 动态灵动岛美化样式代码 结束 !-->

[/hidecontent]

3.将以下代码添加到 zibll 文件夹中的 function.php 或 func.php 文件里。

[hidecontent type=“reply”]

// 灵动岛通知 开始
function add_dynamic_island_script() {
?>
<script type="text/javascript">
window.onload = function() {
// 触发灵动岛的显示
triggerIsland();
// 获取当前页面的标题
let title;
const currentUrl = window.location.pathname;
// 获取当前 URL 路径
if (currentUrl.includes('/message/')) {
// 如果访问了消息页面
document.querySelector('.bars p').innerText = "正在访问消息页面";
} else if (currentUrl.includes('/user/')) {
// 如果访问了用户中心页面
document.querySelector('.bars p').innerText = "欢迎来到用户中心";
} else if (document.body.classList.contains('home') || document.body.classList.contains('front-page')) {
// 如果是首页
document.querySelector('.bars p').innerText = "欢迎来到<a target="_blank" href="https://yinhenote.cn/tag/%e9%93%b6%e6%b2%b3%e7%ac%94%e8%ae%b0/" title="View all posts in 银河笔记">银河笔记</a>";
} else if (document.body.classList.contains('single')) {
// 如果是单篇文章
title = "<?php echo addslashes(html_entity_decode(get_the_title())); ?>";
// 获取文章标题并解码
document.querySelector('.bars p').innerText = "正在访问:" + title;
} else if (document.body.classList.contains('category')) {
// 如果是分类页面
const category = "<?php echo addslashes(html_entity_decode(get_queried_object()->name)); ?>";
// 获取当前分类的名称
document.querySelector('.bars p').innerText = "正在访问:" + category + " 分类";
} else if (document.body.classList.contains('page')) {
// 如果是单个页面
title = "<?php echo addslashes(html_entity_decode(get_the_title())); ?>";
// 获取页面标题并解码
document.querySelector('.bars p').innerText = "正在访问:" + title;
} else {
// 如果以上都不匹配,可以使用默认值
document.querySelector('.bars p').innerText = "欢迎来到极客指北";
}
}
;
// 触发灵动岛的显示
function triggerIsland() {
const island = document.getElementById('dynamicIsland');
if (island) {
island.style.opacity = 1;
island.classList.add('active')
island.classList.remove('inactive');
// 在4秒后触发关闭动画
setTimeout(() => {
closeIsland();
}
, 4000);
}
}
function closeIsland() {
const island = document.getElementById('dynamicIsland')
if (island) {
island.classList.remove('active');
island.classList.add('inactive');
setTimeout(() => {
island.style.opacity = 0;
// 使灵动岛透明
}
, 600);
// 与 transform 动画持续时间一致
}
}
</script>
<?php
}
add_action('wp_head', 'add_dynamic_island_script');
// 灵动岛 结束

[/hidecontent]

按教程操作完成后,记得保存所作更改,然后刷新网站,就能亲眼见证动态灵动岛的炫酷效果啦!

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或赞助支持!

赞助
子比美化 – 为网站添加一个动态灵动岛
https://blog.90svip.cn/posts/post-104/
作者
小北
发布于
2025-06-15
许可协议
CC BY-NC-SA 4.0
相关文章 智能推荐
1
子比美化 - 另类方法实现首页底部添加友情链接
经验分享 前言 子比主题首页底部没有什么可以直接显示友链接的地方,所以找了下别人的方法,借鉴实现了。 效果展示 实现方法 后台选择外观-小工具-zibll链接列表(新版)放到首页-底部全宽度,然后根据我的设置修改保存即可。 我使用的是图文模式,可以显示你设置的网站图标,根据自己的情况可以选择极简模式等,效果可以自己看。
2
子比美化 - 文章缩略图鼠标悬停自定义图片
经验分享 效果展示 设置教程 进入子比主题设置,找到“自定义代码”部分,再找到“自定义 CSS 样式”区域。 将以下代码复制并粘贴到自定义 CSS 样式区域中。这段代码将为你的特色图片添加一个模糊的蒙版效果,并在鼠标悬停时显示一张小图标。 [hidecontent type="reply"] /*文章缩略图悬停样式*/ .item-thumbnail {position:...
3
使用Aplayer+Meting Api为你的博客文章内加入音乐播放器
经验分享 前言 因为我经常喜欢在博客里分享音乐,所以我也在找可以插入文章的音乐播放器,但是一直没找到,所以只能自己想办法琢磨了,最后的解决办法就是今天这篇文章。 效果演示 Meting.js 介绍 Meting.js 依赖 APlayer.js,扩展了 APlayer.js 的功能,能够使 APlayer.js 加载网易云音乐、QQ 音乐、虾米音乐中的歌单。 实现方法...
4
Telegram 提示“短信收费”的完整解决方案
经验分享 Telegram 登录弹出“SMS Fee/短信收费”?教你免费绕过! 最近很多人在使用 Telegram 的时候,都会遇到一个非常离谱的提示: SMS Fee / 短信收费 。 无论是 登录老账号 ,还是 注册新账号 ,都会突然弹出提示,让你先支付短信费用才能继续操作。 很多人就懵了: 这个钱到底该不该交? 交了会不会被骗? 有没有办法绕过这个收费? 这篇文章,我把目前 成功率最高的解决方案...
5
3分钟注册外区苹果ID教程(无需翻墙、无需信用卡)
经验分享 3分钟注册外区苹果ID教程(无需翻墙、无需信用卡) 很多用户在使用 Apple 设备时,都会遇到一个问题: 为什么很多海外应用在国内 App Store 下载不了? 答案很简单—— 地区限制 。 今天这篇文章,教你用 最简单的方法 ,3分钟注册一个外区苹果ID(美区 / 港区 / 台区均可),而且: 不需要翻墙 不需要外区信用卡 支持国内手机号 + 邮箱 一、注册前准备...
随机文章 随机推荐

评论区

Profile Image of the Author
小北
我很感谢那些任凭时光流逝却依旧陪在我身边的人。
公告
欢迎来到我的博客!这是一则示例公告。
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
25
分类
5
标签
69
总字数
17,669
运行时长
0
最后活动
0 天前

文章目录