![[亲测可用]子比主题首页和文章内添加一个灵动岛样式美化代码](https://yizhi2024.top/wp-content/uploads/2025/01/20250118155745659-学社山中人_2025-01-18_15-57-32.webp)
原帖链接:https://www.zibll.com/forum-post/32727.html
代码部署情况如下
主题设置—自定义CSS代码
.dynamic-island:hover img {width:30px; height:30px;;}
.bars {display:flex;align-items:center; justify-content:flex-end; gap:3px;}
.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;}
.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);;}
.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:right; width:100%;}
.dynamic-island.active .island-content {opacity:1;}
.dynamic-island img {position:absolute;left:10px; 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;}
@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;}
;}
主题设置—自定义头部HTML
<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>
主题文件夹中的function.php或func.php文件中
function add_dynamic_island_script() {
?>
<script type="text/javascript">
window.onload = function() {
triggerIsland();
let title;
const currentUrl = window.location.pathname;
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 = "欢迎来到<?php echo get_bloginfo('name'); ?>";
} 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 = "欢迎来到<?php echo get_bloginfo('name'); ?>";
}
}
;
function triggerIsland() {
const island = document.getElementById('dynamicIsland');
if (island) {
island.style.opacity = 1;
island.classList.add('active')
island.classList.remove('inactive');
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);
}
}
</script>
<?php
}
add_action('wp_footer', 'add_dynamic_island_script');
标题带有亲测,是经过一定测试的源码或工具;破解软件或绿色软件一般都会报毒,如果您害怕,请勿下载安装,感谢
© 版权声明
THE END
相关推荐

![[亲测可用]子比主题网站会员点击会员按钮依然能进入会员页面-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/11/20241125195451688-学社山中人_2024-11-25_19-54-42.webp)

![鼠标移动到文章标题变色[子比主题美化教程]-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/04/Snipaste_2024-04-07_21-41-49-1024x469.png)

![[亲测可用]网站免费天气代码-添加实时天气教程-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/11/20241125200837690-学社山中人_2024-11-25_20-08-22.webp)
![[亲测可用]子比主题去除文章页面作者信息板块-子比主题美化-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/10/20241008144538199-学社山中人_2024-10-08_14-44-24.webp)
![[亲测可用]IDM6.42免费安装已激活pj版-重新打包版(Windows软件)-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/09/20240925213046592-学社山中人_2024-09-25_21-30-24.webp)
![[亲测搭建可用]美女写真打赏视频打赏系统2024.3.31(带有视频搭建教程和使用教程)-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/03/image-49.png)

![[亲测可用]美团京东拼多多代付三合一版本代付源码(搭建教程+配置教程)-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/09/20240913000623356-1.webp)
![[亲测可用]易支付/码支付使用教程(梦码助手)24.07.28-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/05/image-58-1024x469.png)
![[亲测可用]写真视频打赏源码网站子比二开写真视频打赏网站源码-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/08/20240830165645811-下载.jpg)
![[亲测可搭建]模特写真网源码+数据库—zblog内核-学社山中人](https://yizhi2024.top/wp-content/uploads/2024/05/image-97-1024x469.png)
![[亲测可用]一键关闭win10自动更新本地免安装-电脑软件-学社山中人](https://yizhi2024.top/wp-content/uploads/2025/01/20250102171808629-学社山中人_2025-01-02_17-16-51.webp)
