博主

7小时前在线

MAO486
一个宅的新“家”
博主 MAO486
博主 7小时前 在线自豪地使用 Typecho 建站搭配使用 🌻Sunny 主题当前在线 10 人
歌曲封面 未知作品

网站已运行 193 天 15 小时 54 分

Powered by Typecho & Sunny

11 online · 97 ms

Title

进度条短代码

某昴

·

📦杂

·

Article

[✌️progress value=75](去掉Emoji)
[progress value=75]

♾️ php 代码:
    <?php
// 解析进度条短代码
function parseProgressBarShortcode($content) {
    return preg_replace_callback('/\[progress\s+value=(\d+)\]/', function ($matches) {
        $currentProgress = intval($matches[1]);
        $currentProgress = max(0, min(100, $currentProgress)); // 限制范围为 0-100%

        // 计算已填充的宽度
        $filledWidth = $currentProgress . '%';

        // 生成带有文本的进度条
        return "
            <div style='position: relative; width: 100%; height: 30px; background: #f3f3f3; border-radius: 10px; overflow: hidden; border: 1px solid #ddd;'>
                <div style='width: $filledWidth; height: 100%; background: #4caf50; display: flex; align-items: center; justify-content: center;'>
                    <span style='color: white; font-weight: bold;'>进度: {$currentProgress}%</span>
                </div>
            </div>
        ";
    }, $content);
}

// 注册短代码解析钩子
Typecho_Plugin::factory('Widget_Abstract_Contents')->contentEx = 'parseProgressBarShortcode';
Typecho_Plugin::factory('Widget_Abstract_Contents')->excerptEx = 'parseProgressBarShortcode';
?>
现在已有 16 次阅读,0 条评论,0 人点赞
Comment:共0条
发表
搜 索 消 息 足 迹
你还不曾留言过..
你还不曾留下足迹..
博主 不再显示
博主