经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » HTML5 » 查看文章
博客园美化大全
来源:cnblogs  作者:子钦加油  时间:2019/8/8 8:51:02  对本文有异议

1.1、自动生成目录

效果如下:

 

(1)页脚js代码

首先得有js权限

复制代码
  1. <script type="text/javascript">
  2. /*
  3. 功能:生成博客目录的JS工具
  4. 测试:IE8,火狐,google测试通过
  5. zhang_derek
  6. 2018-01-03
  7. */
  8. var BlogDirectory = {
  9. /*
  10. 获取元素位置,距浏览器左边界的距离(left)和距浏览器上边界的距离(top)
  11. */
  12. getElementPosition:function (ele) {
  13. var topPosition = 0;
  14. var leftPosition = 0;
  15. while (ele){
  16. topPosition += ele.offsetTop;
  17. leftPosition += ele.offsetLeft;
  18. ele = ele.offsetParent;
  19. }
  20. return {top:topPosition, left:leftPosition};
  21. },
  22.  
  23. /*
  24. 获取滚动条当前位置
  25. */
  26. getScrollBarPosition:function () {
  27. var scrollBarPosition = document.body.scrollTop || document.documentElement.scrollTop;
  28. return scrollBarPosition;
  29. },
  30. /*
  31. 移动滚动条,finalPos 为目的位置,internal 为移动速度
  32. */
  33. moveScrollBar:function(finalpos, interval) {
  34.  
  35. //若不支持此方法,则退出
  36. if(!window.scrollTo) {
  37. return false;
  38. }
  39.  
  40. //窗体滚动时,禁用鼠标滚轮
  41. window.onmousewheel = function(){
  42. return false;
  43. };
  44. //清除计时
  45. if (document.body.movement) {
  46. clearTimeout(document.body.movement);
  47. }
  48.  
  49. var currentpos =BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
  50.  
  51. var dist = 0;
  52. if (currentpos == finalpos) {//到达预定位置,则解禁鼠标滚轮,并退出
  53. window.onmousewheel = function(){
  54. return true;
  55. }
  56. return true;
  57. }
  58. if (currentpos < finalpos) {//未到达,则计算下一步所要移动的距离
  59. dist = Math.ceil((finalpos - currentpos)/10);
  60. currentpos += dist;
  61. }
  62. if (currentpos > finalpos) {
  63. dist = Math.ceil((currentpos - finalpos)/10);
  64. currentpos -= dist;
  65. }
  66. var scrTop = BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
  67. window.scrollTo(0, currentpos);//移动窗口
  68. if(BlogDirectory.getScrollBarPosition() == scrTop)//若已到底部,则解禁鼠标滚轮,并退出
  69. {
  70. window.onmousewheel = function(){
  71. return true;
  72. }
  73. return true;
  74. }
  75. //进行下一步移动
  76. var repeat = "BlogDirectory.moveScrollBar(" + finalpos + "," + interval + ")";
  77. document.body.movement = setTimeout(repeat, interval);
  78. },
  79. htmlDecode:function (text){
  80. var temp = document.createElement("div");
  81. temp.innerHTML = text;
  82. var output = temp.innerText || temp.textContent;
  83. temp = null;
  84. return output;
  85. },
  86.  
  87. /*
  88. 创建博客目录,
  89. id表示包含博文正文的 div 容器的 id,
  90. mt 和 st 分别表示主标题和次级标题的标签名称(如 H2、H3,大写或小写都可以!),
  91. interval 表示移动的速度
  92. */
  93. createBlogDirectory:function (id, mt, st, interval){
  94. //获取博文正文div容器
  95. var elem = document.getElementById(id);
  96. if(!elem) return false;
  97. //获取div中所有元素结点
  98. var nodes = elem.getElementsByTagName("*");
  99. //创建博客目录的div容器
  100. var divSideBar = document.createElement('DIV');
  101. divSideBar.className = 'uprightsideBar';
  102. divSideBar.setAttribute('id', 'uprightsideBar');
  103. var divSideBarTab = document.createElement('DIV');
  104. divSideBarTab.setAttribute('id', 'sideBarTab');
  105. divSideBar.appendChild(divSideBarTab);
  106. var h2 = document.createElement('H2');
  107. divSideBarTab.appendChild(h2);
  108. var txt = document.createTextNode('目录导航');
  109. h2.appendChild(txt);
  110. var divSideBarContents = document.createElement('DIV');
  111. divSideBarContents.style.display = 'none';
  112. divSideBarContents.setAttribute('id', 'sideBarContents');
  113. divSideBar.appendChild(divSideBarContents);
  114. //创建自定义列表
  115. var dlist = document.createElement("dl");
  116. divSideBarContents.appendChild(dlist);
  117. var num = 0;//统计找到的mt和st
  118. mt = mt.toUpperCase();//转化成大写
  119. st = st.toUpperCase();//转化成大写
  120. //遍历所有元素结点
  121. for(var i=0; i<nodes.length; i++)
  122. {
  123. if(nodes[i].nodeName == mt|| nodes[i].nodeName == st)
  124. {
  125. //获取标题文本
  126. var nodetext = nodes[i].innerHTML.replace(/<\/?[^>]+>/g,"");//innerHTML里面的内容可能有HTML标签,所以用正则表达式去除HTML的标签
  127. nodetext = nodetext.replace(/ /ig, "");//替换掉所有的
  128. nodetext = BlogDirectory.htmlDecode(nodetext);
  129. //插入锚
  130. nodes[i].setAttribute("id", "blogTitle" + num);
  131. var item;
  132. switch(nodes[i].nodeName)
  133. {
  134. case mt: //若为主标题
  135. item = document.createElement("dt");
  136. break;
  137. case st: //若为子标题
  138. item = document.createElement("dd");
  139. break;
  140. }
  141. //创建锚链接
  142. var itemtext = document.createTextNode(nodetext);
  143. item.appendChild(itemtext);
  144. item.setAttribute("name", num);
  145. item.onclick = function(){ //添加鼠标点击触发函数
  146. var pos = BlogDirectory.getElementPosition(document.getElementById("blogTitle" + this.getAttribute("name")));
  147. if(!BlogDirectory.moveScrollBar(pos.top, interval)) return false;
  148. };
  149. //将自定义表项加入自定义列表中
  150. dlist.appendChild(item);
  151. num++;
  152. }
  153. }
  154. if(num == 0) return false;
  155. /*鼠标进入时的事件处理*/
  156. divSideBarTab.onmouseenter = function(){
  157. divSideBarContents.style.display = 'block';
  158. }
  159. /*鼠标离开时的事件处理*/
  160. divSideBar.onmouseleave = function() {
  161. divSideBarContents.style.display = 'none';
  162. }
  163.  
  164. document.body.appendChild(divSideBar);
  165. }
  166. };
  167.  
  168. window.onload=function(){
  169. /*页面加载完成之后生成博客目录*/
  170. BlogDirectory.createBlogDirectory("cnblogs_post_body","h2","h3",20);
  171. }
  172. </script>
复制代码

(2)页面定制css代码

复制代码
  1. /*生成博客目录的CSS*/
  2. #uprightsideBar{
  3. font-size:14px;
  4. font-family:Arial, Helvetica, sans-serif;
  5. text-align:left;
  6. position:fixed;/*将div的位置固定到距离top:50px,right:0px的位置,这样div就会处在最右边的位置,距离顶部50px*/
  7. top:400px;
  8. right:53px;
  9. width: auto;
  10. height: auto;
  11. }
  12. #sideBarTab{
  13. float:left;
  14. width:30px;
  15. border:1px solid #e5e5e5;
  16. border-right:none;
  17. text-align:center;
  18. background:rgb(238, 130, 238);
  19. }
  20.  
  21. #sideBarContents{
  22. float:left;
  23. overflow:auto;
  24. overflow-x:hidden;!important;
  25. width:200px;
  26. min-height:108px;
  27. max-height:460px;
  28. border:1px solid #e5e5e5;
  29. border-right:none;
  30. background:#ffffff;
  31. }
  32. #sideBarContents dl{
  33. margin:0;
  34. padding:0;
  35. }
  36.  
  37. #sideBarContents dt{
  38. margin-top:5px;
  39. margin-left:5px;
  40. }
  41.  
  42. #sideBarContents dd, dt {
  43. cursor: pointer;
  44. }
  45.  
  46. #sideBarContents dd:hover, dt:hover {
  47. color:#A7995A;
  48. }
  49. #sideBarContents dd{
  50. margin-left:20px;
  51. }
复制代码

 

1.2.增加返回顶部按钮

(1)页面定制css代码

复制代码
  1. #back-to-top {
  2. background-color: #00CD00;
  3. bottom: 0;
  4. box-shadow: 0 0 6px #00CD00;
  5. color: #444444;
  6. padding: 10px 10px;
  7. position: fixed;
  8. right: 50px;
  9. cursor: pointer;
  10. }
复制代码

(2)页首html代码

  1. <span id="back-to-top"><a href="#top">返回顶部</a></span>

 

1.3.爱心特效(鼠标点击页面)

鼠标点击页面效果:

把下面代码复制到公告栏里面

复制代码
  1. <!-- 爱心特效 -->
  2. <script type="text/javascript">
  3.  
  4. (function(window,document,undefined){
  5. var hearts = [];
  6. window.requestAnimationFrame = (function(){
  7. return window.requestAnimationFrame ||
  8. window.webkitRequestAnimationFrame ||
  9. window.mozRequestAnimationFrame ||
  10. window.oRequestAnimationFrame ||
  11. window.msRequestAnimationFrame ||
  12. function (callback){
  13. setTimeout(callback,1000/60);
  14. }
  15. })();
  16. init();
  17. function init(){
  18. css(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
  19. attachEvent();
  20. gameloop();
  21. }
  22. function gameloop(){
  23. for(var i=0;i<hearts.length;i++){
  24. if(hearts[i].alpha <=0){
  25. document.body.removeChild(hearts[i].el);
  26. hearts.splice(i,1);
  27. continue;
  28. }
  29. hearts[i].y--;
  30. hearts[i].scale += 0.004;
  31. hearts[i].alpha -= 0.013;
  32. hearts[i].el.style.cssText = "left:"+hearts[i].x+"px;top:"+hearts[i].y+"px;opacity:"+hearts[i].alpha+";transform:scale("+hearts[i].scale+","+hearts[i].scale+") rotate(45deg);background:"+hearts[i].color;
  33. }
  34. requestAnimationFrame(gameloop);
  35. }
  36. function attachEvent(){
  37. var old = typeof window.onclick==="function" && window.onclick;
  38. window.onclick = function(event){
  39. old && old();
  40. createHeart(event);
  41. }
  42. }
  43. function createHeart(event){
  44. var d = document.createElement("div");
  45. d.className = "heart";
  46. hearts.push({
  47. el : d,
  48. x : event.clientX - 5,
  49. y : event.clientY - 5,
  50. scale : 1,
  51. alpha : 1,
  52. color : randomColor()
  53. });
  54. document.body.appendChild(d);
  55. }
  56. function css(css){
  57. var style = document.createElement("style");
  58. style.type="text/css";
  59. try{
  60. style.appendChild(document.createTextNode(css));
  61. }catch(ex){
  62. style.styleSheet.cssText = css;
  63. }
  64. document.getElementsByTagName('head')[0].appendChild(style);
  65. }
  66. function randomColor(){
  67. return "rgb("+(~~(Math.random()*255))+","+(~~(Math.random()*255))+","+(~~(Math.random()*255))+")";
  68. }
  69. })(window,document);
  70.  
  71. </script>
复制代码

 

1.4.公告栏时钟

公告里面

复制代码
  1. <div id="myTime">
  2. <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="160" height="70" id="honehoneclock" align="middle">
  3. <param name="allowScriptAccess" value="always">
  4. <param name="movie" value="http://chabudai.sakura.ne.jp/blogparts/honehoneclock/honehone_clock_wh.swf">
  5. <param name="quality" value="high">
  6. <param name="bgcolor" value="#ffffff">
  7. <param name="wmode" value="transparent">
  8. <embed wmode="transparent" src="http://chabudai.sakura.ne.jp/blogparts/honehoneclock/honehone_clock_wh.swf" quality="high" bgcolor="#ffffff" width="160" height="70" name="honehoneclock" align="middle" allowscriptaccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
  9. </object>
  10. </div>
复制代码

 

1.5.公告栏里面添加信息

公告里面

  • 图片路径:可以把图片上传到你的博客相册里面,然后把图片地址复制过来就可以
复制代码
  1. <p class="gonggao">&nbsp<a style="color: blue;font-weight: bold;" href="http://www.cnblogs.com/derek1184405959/p/8579428.html">我的博客文章(目录)</a></p>
  2. <p class="qq">&nbsp;写自己想要的一些信息</p>
  3.  
  4. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style="color:red;" title="点此进入Django2.0官方文档" target="_Blank" href="https://docs.djangoproject.com/en/2.0/"><img src="http://images.cnblogs.com/cnblogs_com/derek1184405959/1210823/t_django.jpg" alt="zzx" class="img_avatar" width="170px" height="80px" style="border-radius:0%" > </a>
复制代码

 css代码

复制代码
  1. .qq{
  2. color:red;
  3. font-size:15px;
  4. margin:8px;
  5. font-weight: 500;
  6. }
  7. .gonggao{
  8. margin:8px;
  9. font-size:16px;
  10. color:blue;
  11. }
复制代码

 

1.6.添加github图标

页首html代码

只要把a标签里面的地址换成你自己的就可以

复制代码
  1. <a href="https://github.com/derek-zhang123/" title="我的github地址" target="_Blank" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#FD6C6C; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
  2.  
  3.  
  4.  
  5. <a href="http://www.cnblogs.com/derek1184405959/" title="我的博客主页" target="_Blank" class="github-corner" aria-label="View source on Github"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#64CEAA; color:#fff; position: absolute; top: 0; border: 0; left: 0; transform: scale(-1, 1);" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
复制代码

 

1.7.扩大和缩小功能

效果:

点“扩大”,左边的侧边栏会隐藏,点“缩小”侧边栏又会恢复

(1)页首html代码

  1. <div id="divExpandViewArea" onclick="$('#main_container').css({'margin-left':'-200px'});$('#leftmenu').css({'display':'none'});">扩大</div>
  2. <div id="divCollapseViewArea" onclick="$('#main_container').css({'margin-left':'0px'});$('#leftmenu').css({'display':'block'});">缩小</div>

(2)页面定制css样式

复制代码
  1. #divExpandViewArea{
  2. position: fixed;
  3. color: white;
  4. padding: 10px 10px;
  5. left: 0px;
  6. top: 547px;
  7. cursor: pointer;
  8. opacity: 0.9;
  9. background-color: #68228B;
  10. }
  11. #divCollapseViewArea{
  12. position: fixed;
  13. color: white;
  14. padding: 10px 10px;
  15. left: 0px;
  16. top: 586px;
  17. cursor: pointer;
  18. opacity: 0.9;
  19. background-color: #68228B;
  20. }
复制代码

 

1.8.设置签名格式

效果如下:

页面定制css样式

复制代码
  1. /* 设置签名格式 */
  2. #MySignature {
  3. display: none;
  4. background-color: #B2E866;
  5. border-radius: 10px;
  6. box-shadow: 1px 1px 1px #6B6B6B;
  7. padding: 10px;
  8. line-height: 1.5;
  9. text-shadow: 1px 1px 1px #FFF;
  10. font-size: 16px;
  11. font-family: 'Microsoft Yahei';
  12. }
复制代码

 

1.9.设置随笔分类间距

左侧随笔分类之间间距

页面定制css样式

复制代码
  1. /* 左侧最新随笔 */
  2. #CatList_LinkList_0_Link_0{
  3. }
  4. #CatList_LinkList_0_Link_1{
  5. margin-top:10px;
  6. }
  7. #CatList_LinkList_0_Link_2{
  8. margin-top:10px;
  9. }
  10. #CatList_LinkList_0_Link_3{
  11. margin-top:10px;
  12.  
  13. }
  14. #CatList_LinkList_0_Link_4{
  15. margin-top:10px;
  16.  
  17. }
  18. #CatList_LinkList_0_Link_5{
  19. margin-top:10px;
  20.  
  21. }
  22. #CatList_LinkList_0_Link_6{
  23. margin-top:10px;
  24.  
  25. }
  26. #CatList_LinkList_0_Link_7{
  27. margin-top:10px;
  28.  
  29. }
  30. #CatList_LinkList_0_Link_8{
  31. margin-top:10px;
  32.  
  33. }
复制代码

 

1.10.添加分享功能

效果如下:

 

公告栏里面

复制代码
  1. <script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"slide":{"type":"slide","bdImg":"6","bdPos":"right","bdTop":"400"},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到:","viewSize":"16"}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
复制代码

 

1.11.走马灯

 页首html代码

复制代码
  1. <div id="i1" style="color:red;font-size:13px;padding:5px;">大江东去,浪淘尽,千古风流人物。故垒西边,人道是,三国周郎赤壁。乱石穿空,惊涛拍岸,卷起千堆雪。江山如画,一时多少豪杰。遥想公瑾当年,小乔初嫁了,雄姿英发。羽扇纶巾,谈笑间,樯橹灰飞烟灭。故国神游,多情应笑我,早生华发。人生如梦,一尊还酹江月。</div>
  2. <script>
  3. function func(){
  4. var tag = document.getElementById('i1');
  5. var content = tag.innerText;
  6. var f = content.charAt(0);
  7. var l = content.substring(1,content.length);
  8. var new_content = l + f;
  9. tag.innerText = new_content;
  10. }
  11. setInterval('func()',1600);
  12. </script>
复制代码

 

1.12.推荐和反对

页面定制css

复制代码
  1. /*推荐和反对*/
  2. #div_digg {
  3. padding: 10px;
  4. position: fixed;
  5. _position: absolute;
  6. z-index: 1000;
  7. bottom: 20px;
  8. right: 0;
  9. _right: 17px;
  10. border: 1px solid #D9DBE1;
  11. background-color: #FFFFFF;
  12. filter: alpha(Opacity=80);
  13. -moz-opacity: 1;
  14. opacity: 1;
  15. }
  16.  
  17. .icon_favorite {
  18. background: transparent url('http://files.cnblogs.com/files/jackson0714/kj.gif') no-repeat 0 0;
  19. padding-left: 16px;
  20. }
复制代码

原文链接:http://www.cnblogs.com/zmdComeOn/p/11315677.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号