过年啦,挂灯笼!

过年挂灯笼是中国的一个习俗,家里挂灯笼,自己博客也是自己的家,当然也要挂一个了。很多年前Flash流行时,网上可以随便找一个Flash动画的灯笼,很方便就可以加到网站主题模板上,如今Flash已成过眼云烟,在国内甚至已变成流氓插件,网上找了找没有合适CSS3动画灯笼,在知更鸟博客找到了,效果如图。

代码这里也分享一下,有喜欢的朋友拿去用,将灯笼挂在自己的博客上,增加点过年的气氛。

这个灯笼只是简单应用一下CSS3动画,纯HTML+CSS手敲出来的,由于时间短写的不是很严谨,但不影响使用,具体实现方法,文章最后有打包文件下载。

第一步、添加HTML代码

将下面的HTML代码添加到主题页脚模板footer.php,</body>标签的上面。

  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. .dengbox {
  2. position: fixed;
  3. top: 40px;
  4. right: 20px;
  5. zindex: 999;
  6. }
  7. .dengbox1 {
  8. position: fixed;
  9. top: 30px;
  10. right: 10px;
  11. zindex: 999;
  12. }
  13. .dengbox1 .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. borderradius: 50% 50%;
  21. webkittransformorigin: 50% 100px;
  22. webkitanimation: swing 5s infinite easeinout;
  23. boxshadow: 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. borderradius: 50% 50%;
  33. webkittransformorigin: 50% 100px;
  34. webkitanimation: swing 3s infinite easeinout;
  35. boxshadow: 5px 5px 50px 4px rgba(250, 108, 0, 1);
  36. }
  37. .denga {
  38. width: 100px;
  39. height: 90px;
  40. background: #d8000f;
  41. background: rgba(216, 0, 15, 0.1);
  42. margin: 12px 8px 8px 10px;
  43. borderradius: 50% 50%;
  44. border: 2px solid #dc8f03;
  45. }
  46. .dengb {
  47. width: 45px;
  48. height: 90px;
  49. background: #d8000f;
  50. background: rgba(216, 0, 15, 0.1);
  51. margin: 4px 8px 8px 26px;
  52. borderradius: 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. .shuia {
  64. position: relative;
  65. width: 5px;
  66. height: 20px;
  67. margin: 5px 0 0 59px;
  68. webkitanimation: swing 4s infinite easeinout;
  69. webkittransformorigin: 50% 45px;
  70. background: #ffa500;
  71. borderradius: 0 0 5px 5px;
  72. }
  73. .shuib {
  74. position: absolute;
  75. top: 14px;
  76. left: 2px;
  77. width: 10px;
  78. height: 10px;
  79. background: #dc8f03;
  80. borderradius: 50%;
  81. }
  82. .shuic {
  83. position: absolute;
  84. top: 18px;
  85. left: 2px;
  86. width: 10px;
  87. height: 35px;
  88. background: #ffa500;
  89. borderradius: 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. zindex: 999;
  100. borderradius: 5px 5px 0 0;
  101. border: solid 1px #dc8f03;
  102. background: #ffa500;
  103. background: lineargradient(to right, #dc8f03, #ffa500, #dc8f03, #ffa500, #dc8f03);
  104. }
  105. .deng:after {
  106. position: absolute;
  107. bottom: 7px;
  108. left: 10px;
  109. height: 12px;
  110. width: 60px;
  111. content: ” “;
  112. display: block;
  113. marginleft: 20px;
  114. borderradius: 0 0 5px 5px;
  115. border: solid 1px #dc8f03;
  116. background: #ffa500;
  117. background: lineargradient(to right, #dc8f03, #ffa500, #dc8f03, #ffa500, #dc8f03);
  118. }
  119. .dengt {
  120. fontfamily: 华文行楷,Arial,Lucida Grande,Tahoma,sansserif;
  121. fontsize: 3.2rem;
  122. color: #dc8f03;
  123. fontweight: bold;
  124. lineheight: 85px;
  125. textalign: center;
  126. }
  127. .night .dengt,
  128. .night .dengbox,
  129. .night .dengbox1 {
  130. background: transparent !important;
  131. }
  132. @-mozkeyframes swing {
  133. 0% {
  134. moztransform: rotate(-10deg)
  135. }
  136. 50% {
  137. moztransform: rotate(10deg)
  138. }
  139. 100% {
  140. moztransform: rotate(-10deg)
  141. }
  142. }
  143. @-webkitkeyframes swing {
  144. 0% {
  145. webkittransform: rotate(-10deg)
  146. }
  147. 50% {
  148. webkittransform: rotate(10deg)
  149. }
  150. 100% {
  151. webkittransform: rotate(-10deg)
  152. }
  153. }

发表回复

您的电子邮箱地址不会被公开。