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

为网站添加一个灵动岛样式美化代码

图片[1]-子比美化 – 为网站添加一个动态灵动岛-零染收集blog

只需简单三步,你就能轻松拥有同款动态灵动岛。本教程特别适用于子比主题,其他主题的朋友们可自行测试哦~

第一步 添加动态灵动岛美化样式代码至自定义 CSS

将以下精心设计的动态灵动岛美化样式代码,添加到网站的自定义 css 区域。这段代码巧妙地定义了灵动岛在不同状态下的样式,包括鼠标悬停时的变化,以及条形波动的动画效果等,让你的灵动岛更加生动有趣。

/* 动态灵动岛美化样式代码*/
.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;
    }
}
/* 动态灵动岛美化样式代码 结束*/

第二步 添加代码至后台自定义头部 HTML

接着,把下面这段代码添加到后台的自定义头部 html 中。此代码构建了灵动岛的基本结构,包含图片、提示文字以及波动的条形元素,为灵动岛的显示奠定基础。

第三步 添加代码至 zibll 文件夹中的特定文件

最后一步,将以下代码添加到 zibll 文件夹中的 function.php 或 func.php 文件里。这段代码通过 JavaScript 实现了灵动岛的动态逻辑,根据不同的页面状态显示相应的提示信息,并控制灵动岛的显示与关闭动画,让整个效果更加流畅自然。

请务必注意,这三步操作环环相扣,缺一不可。按教程操作完成后,记得保存所作更改,然后刷新网站,就能亲眼见证动态灵动岛的炫酷效果啦!

如果不想那么麻烦的话可以使用插件,直接安装即可使用

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容