为 WordPress 主题添加大红灯笼特效

  • 时间:2020-05-17 12:16:18
  • 分类:网络文摘
  • 阅读:115 次

前两天分享了一个为wordpress主题添加花瓣飘落的特效,今天再来分享一个为wordpress主题添加大红灯笼的特效,可以让你的博客在过年的时候节日氛围更浓。此特效同样出自知更鸟,是CSS3动画的简单应用,纯HTML+CSS手敲出来的。在文章最后有代码文件的压缩包下载及具体使用方法。

点击下图查看动画效果

特效演示

第一步、添加HTML代码

添加如下 HTML 代码到当前主题页脚模板 footer.php 中的 <?php wp_footer(); ?> 标签上面。

  1. <!-- 灯笼1 -->
  2. <div class="deng-box">
  3.     <div class="deng">
  4.         <div class="xian"></div>
  5.         <div class="deng-a">
  6.             <div class="deng-b"><div class="deng-t">节</div></div>
  7.         </div>
  8.         <div class="shui shui-a"><div class="shui-c"></div><div class="shui-b"></div></div>
  9.     </div>
  10. </div>
  11. <!-- 灯笼2 -->
  12. <div class="deng-box1">
  13.     <div class="deng">
  14.         <div class="xian"></div>
  15.         <div class="deng-a">
  16.             <div class="deng-b"><div class="deng-t">春</div></div>
  17.         </div>
  18.         <div class="shui shui-a"><div class="shui-c"></div><div class="shui-b"></div></div>
  19.     </div>
  20. </div>

因代码中有中文,编辑后需将模板文件保存为UTF-8 无BOM(无签名)的格式,后台主题编辑中修改可以忽略,上面的代码可以只加一个,个人感觉挂两个灯笼更灵动些。

如果只想在首页显示灯笼,可以用下面的判断语句把HTML代码包裹起来:

  1. <?php if (is_home()) { ?>
  2. <!-- 代码放这里 -->
  3. <?php } ?>

 

第二步、添加样式代码

将样式代码添加到WP后台 → 外观 → 自定义 → 额外CSS 中,点击“发布”即可。

  1. .deng-box {
  2.     position: fixed;
  3.     top: -40px;
  4.     rightright: -20px;
  5.     z-index: 999;
  6. }
  7. .deng-box1 {
  8.     position: fixed;
  9.     top: -30px;
  10.     rightright: 10px;
  11.     z-index: 999;
  12. }
  13. .deng-box1 .deng {
  14.     position: relative;
  15.     width: 120px;
  16.     height: 90px;
  17.     margin: 50px;
  18.     background: #d8000f;
  19.     background: rgba(216, 0, 15, 0.8);
  20.     border-radius: 50% 50%;
  21.     -webkit-transform-origin: 50% -100px;
  22.     -webkit-animation: swing 5s infinite ease-in-out;
  23.     box-shadow: -5px 5px 30px 4px rgba(252, 144, 61, 1);
  24. }
  25. .deng {
  26.     position: relative;
  27.     width: 120px;
  28.     height: 90px;
  29.     margin: 50px;
  30.     background: #d8000f;
  31.     background: rgba(216, 0, 15, 0.8);
  32.     border-radius: 50% 50%;
  33.     -webkit-transform-origin: 50% -100px;
  34.     -webkit-animation: swing 3s infinite ease-in-out;
  35.     box-shadow: -5px 5px 50px 4px rgba(250, 108, 0, 1);
  36. }
  37. .deng-a {
  38.     width: 100px;
  39.     height: 90px;
  40.     background: #d8000f;
  41.     background: rgba(216, 0, 15, 0.1);
  42.     margin: 12px 8px 8px 10px;
  43.     border-radius: 50% 50%;
  44.     border: 2px solid #dc8f03;
  45. }
  46. .deng-b {
  47.     width: 45px;
  48.     height: 90px;
  49.     background: #d8000f;
  50.     background: rgba(216, 0, 15, 0.1);
  51.     margin: -4px 8px 8px 26px;
  52.     border-radius: 50% 50%;
  53.     border: 2px solid #dc8f03;
  54. }
  55. .xian {
  56.     position: absolute;
  57.     top: -20px;
  58.     left: 60px;
  59.     width: 2px;
  60.     height: 20px;
  61.     background: #dc8f03;
  62. }
  63. .shui-a {
  64.     position: relative;
  65.     width: 5px;
  66.     height: 20px;
  67.     margin: -5px 0 0 59px;
  68.     -webkit-animation: swing 4s infinite ease-in-out;
  69.     -webkit-transform-origin: 50% -45px;
  70.     background: #ffa500;
  71.     border-radius: 0 0 5px 5px;
  72. }
  73. .shui-b {
  74.     position: absolute;
  75.     top: 14px;
  76.     left: -2px;
  77.     width: 10px;
  78.     height: 10px;
  79.     background: #dc8f03;
  80.     border-radius: 50%;
  81. }
  82. .shui-c {
  83.     position: absolute;
  84.     top: 18px;
  85.     left: -2px;
  86.     width: 10px;
  87.     height: 35px;
  88.     background: #ffa500;
  89.     border-radius: 0 0 0 5px;
  90. }
  91. .deng:before {
  92.     position: absolute;
  93.     top: -7px;
  94.     left: 29px;
  95.     height: 12px;
  96.     width: 60px;
  97.     content: " ";
  98.     display: block;
  99.     z-index: 999;
  100.     border-radius: 5px 5px 0 0;
  101.     border: solid 1px #dc8f03;
  102.     background: #ffa500;
  103.     background: linear-gradient(to rightright, #dc8f03, #ffa500, #dc8f03, #ffa500, #dc8f03);
  104. }
  105. .deng:after {
  106.     position: absolute;
  107.     bottombottom: -7px;
  108.     left: 10px;
  109.     height: 12px;
  110.     width: 60px;
  111.     content: " ";
  112.     display: block;
  113.     margin-left: 20px;
  114.     border-radius: 0 0 5px 5px;
  115.     border: solid 1px #dc8f03;
  116.     background: #ffa500;
  117.     background: linear-gradient(to rightright, #dc8f03, #ffa500, #dc8f03, #ffa500, #dc8f03);
  118. }
  119. .deng-t {
  120.     font-family: 华文行楷,Arial,Lucida Grande,Tahoma,sans-serif;
  121.     font-size: 3.2rem;
  122.     color: #dc8f03;
  123.     font-weight: bold;
  124.     line-height: 85px;
  125.     text-align: center;
  126. }
  127. .night .deng-t,
  128. .night .deng-box,
  129. .night .deng-box1 {
  130.     background: transparent !important;
  131. }
  132. @-moz-keyframes swing {
  133.     0% {
  134.         -moz-transform: rotate(-10deg)
  135.     }
  136.     50% {
  137.         -moz-transform: rotate(10deg)
  138.     }
  139.     100% {
  140.         -moz-transform: rotate(-10deg)
  141.     }
  142. }
  143. @-webkit-keyframes swing {
  144.     0% {
  145.         -webkit-transform: rotate(-10deg)
  146.     }
  147.     50% {
  148.         -webkit-transform: rotate(10deg)
  149.     }
  150.     100% {
  151.         -webkit-transform: rotate(-10deg)
  152.     }
  153. }

也可以将样式代码直接加到主题样式文件style.css的最后。可能灯笼上的文字字号在有些主题上显得有点大,可以适当修改第133行的字号:font-size: 3.2rem;

点此下载大红灯笼特效代码文件

使用方法:

一、解压后将 deng.php 文件上传到当前主题根目录中。

二、打开当前主题页脚模板 footer.php,在 <?php wp_footer(); ?> 标签上面添加:

  1. <?php require get_template_directory() . '/deng.php'; ?>

如果只想在首页显示灯笼,可以用下面的判断语句把上面的代码包裹起来。

  1. <?php if (is_home()) { ?>
  2. <!-- 代码放这里 -->
  3. <?php } ?>

如果不想在手机等移动端显示,可将下列代码添加到页脚模板 <?php wp_footer(); ?> 标签的上面。

  1. <?php if (!wp_is_mobile()) { ?>
  2. <?php require get_template_directory() . '/deng.php'; ?>
  3. <?php } ?>

原文:https://zmingcx.com/hanging-lantern.html

推荐阅读:
台湾卫视中文台直播-亚洲卫视中文网「高清」  卫视体育台2在线直播「高清」  卫视国际电影台直播_星空卫视电影台直播「高清」  台湾三立新闻台直播「高清」  台湾年代新闻台直播「高清」  台湾非凡新闻台直播「高清」  耀才财经台直播「流畅」  香港亚太第一卫视ONE-TV直播  凤凰卫视电影台直播_凤凰电影台直播观看  TVB无线财经·资讯台直播观看【高清】 
评论列表
添加评论