"主题编辑"滚动到页面底部,点击"复制一份"创建新配置将配置重命名为便于识别的名称(例如:lantern_control)在配置文件中添加以下内容:fes...">
当前位置:首页 > 技术 > 正文内容

为Halo博客添加新年灯笼效果

访客 技术 2026年5月27日 3

前言

新年将至,为您的博客增添节日氛围。本文将介绍如何在Halo博客中添加精美的灯笼效果,为访客带来浓厚的年味。

一、配置主题设置

首先,我们需要在Halo后台添加一个开关选项,用于控制灯笼的显示。

  1. 登录Halo后台,进入"外观" > "主题编辑"
  2. 滚动到页面底部,点击"复制一份"创建新配置
  3. 将配置重命名为便于识别的名称(例如:lantern_control)

在配置文件中添加以下内容:


    festival_lantern:
      name: festival_lantern
      label: 新年灯笼
      type: switch
      data-type: bool
      default: false
      description: "是否显示新年灯笼装饰"
      options:
        - value: true
          label: 开启
        - value: false
          label: 关闭

二、灯笼效果实现

接下来,我们需要添加灯笼的HTML结构和CSS样式。

HTML结构代码

在主题模板的适当位置添加以下代码:


    <#if settings.festival_lantern == true>
       
       <div class="lantern-container desktop">
           <div class="lantern-wrapper left-lantern">
               <div class="lantern">
                   <div class="lantern-top"></div>
                   <div class="lantern-middle">
                       <div class="lantern-text">春</div>
                   </div>
                   <div class="lantern-bottom"></div>
                   <div class="lantern-cord"></div>
               </div>
           </div>
           
           <div class="lantern-wrapper right-lantern">
               <div class="lantern">
                   <div class="lantern-top"></div>
                   <div class="lantern-middle">
                       <div class="lantern-text">节</div>
                   </div>
                   <div class="lantern-bottom"></div>
                   <div class="lantern-cord"></div>
               </div>
           </div>
       </div>
       
       
       <div class="lantern-container mobile">
           <div class="lantern-wrapper center-lantern">
               <div class="lantern">
                   <div class="lantern-top"></div>
                   <div class="lantern-middle">
                       <div class="lantern-text">春节</div>
                   </div>
                   <div class="lantern-bottom"></div>
                   <div class="lantern-cord"></div>
               </div>
           </div>
       </div>
    

CSS样式代码

在主题的自定义CSS样式中添加以下代码:


    .lantern-container { position:fixed; top:0; left:0; width:100%; height:100%; pointer-events:none; z-index:1000; }
    .lantern-wrapper { position:absolute; }
    .lantern { position:relative; width:120px; height:160px; margin:50px auto; background:#d8000f; background:rgba(216,0,15,0.8); border-radius:50% 50%; animation:swing 5s infinite ease-in-out; transform-origin:50% -100px; -webkit-transform-origin:50% -100px; -webkit-animation:swing 5s infinite ease-in-out; box-shadow:-5px 5px 50px 4px rgba(250,108,0,1); }
    .lantern-top { position:absolute; top:-10px; left:20px; height:20px; width:80px; content:" "; display:block; border-radius:10px 10px 0 0; border:solid 1px #dc8f03; background:#ffa500; background:linear-gradient(to right,#dc8f03,#ffa500,#dc8f03,#ffa500,#dc8f03); }
    .lantern-middle { width:100px; height:120px; background:#d8000f; background:rgba(216,0,15,0.1); margin:10px auto; border-radius:50% 50%; border:2px solid #dc8f03; display:flex; justify-content:center; align-items:center; }
    .lantern-bottom { position:absolute; bottom:-10px; left:20px; height:20px; width:80px; content:" "; display:block; border-radius:0 0 10px 10px; border:solid 1px #dc8f03; background:#ffa500; background:linear-gradient(to right,#dc8f03,#ffa500,#dc8f03,#ffa500,#dc8f03); }
    .lantern-text { font-family:Arial,Lucida Grande,Tahoma,sans-serif; font-size:3.2rem; color:#dc8f03; font-weight:bold; line-height:120px; text-align:center; }
    .lantern-cord { position:absolute; top:-30px; left:60px; width:2px; height:30px; background:#dc8f03; }
    
    @keyframes swing {
      0% { transform:rotate(-8deg); -ms-transform:rotate(-8deg); }
      50% { transform:rotate(8deg); -ms-transform:rotate(8deg); }
      100% { transform:rotate(-8deg); -ms-transform:rotate(-8deg); }
    }
    
    @-webkit-keyframes swing {
      0% { -webkit-transform:rotate(-8deg) }
      50% { -webkit-transform:rotate(8deg) }
      100% { -webkit-transform:rotate(-8deg) }
    }
    
    /* 移动端适配 */
    @media screen and (max-width:768px) {
      .desktop { display:none !important; }
      .mobile { display:block !important; }
      .lantern { width:80px; height:120px; }
      .lantern-text { font-size:2.5rem; line-height:100px; }
      .lantern-top, .lantern-bottom { width:60px; left:30px; }
    }
    
    /* 桌面端适配 */
    @media screen and (min-width:769px) {
      .desktop { display:block !important; }
      .mobile { display:none !important; }
      .left-lantern { left:50px; top:100px; }
      .right-lantern { right:50px; top:100px; }
    }

三、启用灯笼效果

完成以上设置后,进入主题设置页面,找到"新年灯笼"选项,将其设置为"开启",然后保存设置。刷新您的博客页面,即可看到精美的灯笼效果。

通过简单的配置,您的博客在新年期间就能展现出浓厚的节日氛围,为访客带来温馨的视觉体验。

标签: Halo博客

相关文章

Linux crontab 详解

1) crontab 是什么cron 是 Linux 的定时任务守护进程;crontab 是用来编辑/查看“按时间周期执行命令”的表(cron table)。常见两类:用户 crontab:每个用户一份(crontab -e 编辑)系统级 crontab / cron.d:可指定执行用户(/etc/crontab、/etc/cron.d/*)2) crontab 时间...

富文本里可以允许的 HTML 属性

一、所有标签默认允许的安全属性(极少)class        (可选)id           (通常建议禁用)title️ 注意:id 容易被滥用做锚点注入,很多系统直接禁用class 允许的话最好只允许固定前缀(如 editor-*)二、a 标签允许属性<a href="" t...

Mac 安装 Node.js 指南

方法一:通过官网安装包(最简单,适合初学者)如果你只是想快速安装并开始使用,这是最直接的方法。访问 Node.js 官网。页面会显示两个版本:LTS (Recommended For Most Users):长期支持版,最稳定。建议选这个。Current:最新特性版,包含最新功能但可能不够稳定。下载 .pkg 安装包并运行。按照安装向导点击“下一步”即可完成。方法二:使用 Homebrew 安装(...

Dom\HTML_NO_DEFAULT_NS 的副作用:自动加闭合标签

在使用Dom\HTMLDocument时,Dom\HTML_NO_DEFAULT_NS 将禁止在解析过程中设置元素的命名空间, 此设置是为了与DOMDocument向后兼容而存在的。当使用它时,已知的一个副作用就是:自动加闭合标签例如 </img> 为什么会这样?当你使用:Dom\HTML_NO_DEFAULT_NS文档会变成 无命名空间模式,此时内部更接近 XML...

Laravel 事件和监听器创建

在 Laravel 中,使用 Artisan 命令创建 Events(事件) 和 Listeners(监听器) 是非常高效的。你可以通过以下几种方式来实现:1. 手动创建单个 Event如果你只想创建一个事件类,可以使用 make:event 命令:Bashphp artisan make:event UserRegistered执行后,文件将生成在 app/Even...

自定义域名解析神器 dnsmasq

什么是 dnsmasq?dnsmasq 是一个轻量级、功能强大的网络服务工具,专为小型和中等规模网络设计。它是一个综合的网络基础设施解决方案[1]。dnsmasq 能做什么?功能说明应用场景DNS 转发与缓存将 DNS 查询转发到上游服务器(ISP、Google DNS 等),并在本地缓存结果加快 DNS 查询速度,减少外部 DNS 流量本地 DNS解析本地网络设备的主机名,无需编辑&n...

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。