还在为博客页面内容单一而苦恼?来跟我一起定制个人专属博客页面

入园已有两年有余,时有博文发表,博客首页使用的是博客园团队提供的模版,但总感觉页面有些单一。平时在看别人的博客时,都有一些自定义功能,还蛮吸引我的。参考了很多博文,今天来一个总结,将自己的博客美化过程来分享下。

先来整体感受一下,美化后的博客首页,如下所示。虽然谈不上精致,但还是丰富了不少,也自定义了自己想要的内容。

前提条件

在美化首页之前,我们需要先做几个必要事情。

开通js权限

如果没开通该权限,你看到别人的定制效果很好,照葫芦画瓢,将代码复制到自己的设置中,发现会不生效。没申请过的朋友,可能会有疑问了,在哪里能获得这个权限呢?

在你的博客主页点击“管理”---->点击“设置”----下翻找到“申请JS权限”,提交申请即可。

做完这几步,就是静候佳音了,在工作时间内,一般一小时内就会处理;如果时间比较长还没通过,可以给博客园后台发邮件去申请,发给contact@cnblogs.com,有了权限之后就可以开始下面的定制了。有权限显示如下,界面上显示为:支持JS代码

选择模板

我们在使用博客的时候,都是有个模板的。今天分享美化内容,选择的模板是:AnotherEon001。按理说,每个模板都可以这样优化,只是有些内容或按钮显示的不协调而已,需要再次调整下。优化内容仅供参考,每个人都是不一样的烟火,都是自己的独到之处,可以把自己的博客装饰成别具一格的页面。

开始定制

当前期准备做好后,我们就可以开始着手美化自己的博客了。

1.自定义导航栏

我们首先需要做的是,屏蔽调官方模板自带的导航栏,然后才能把自己写好的导航栏加上去,这个导航栏内容你可以自己修改成你自己的,用编辑器修改好代码,然后把它分别粘贴到“页面定制CSS代码”框和“页首HTML代码”框,代码如下:

导航栏CSS定制代码

#header{display:none;} /* 将默认的导航头屏蔽掉 */


/* 定制自己导航栏的样式 */
#shwtop ul {
    margin: 0;
    padding: 0;
    list-style-type: none; /*去除li前的标注*/
    background-color: #333;
    overflow: hidden; /*隐藏溢出的部分,保持一行*/
}
#shwtop li {
    float: left; /*左浮动*/
}
#shwtop li a, .dropbtn {
    display: inline-block; /*设置成块*/
    color: white;
    text-align: center;
    text-decoration: none;
    padding: 14px 16px;
}
/*鼠标移上去,改变背景颜色*/
#shwtop li a:hover, .dropdown:hover .dropbtn { 
    /* 当然颜色你可以自己改成自己喜欢的,我还是挺喜欢蓝色的 */
    background-color: blue;
}
#shwtop .dropdown {
    /*
    display:inline-block将对象呈递为内联对象,
    但是对象的内容作为块对象呈递。
    旁边的内联对象会被呈递在同一行内,允许空格。
    */
    display: inline-block;
}
#shwtop .dropdown-content {
    display: none;
    position: absolute;
    background-color: #f9f9f9;
    min-width: 160px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
}
#shwtop .dropdown-content a {
    display: block;
    color: black;
    padding: 8px 10px;
    text-decoration:none;
}
#shwtop .dropdown-content a:hover {
    background-color: #a1a1a1;
}
#shwtop .dropdown:hover .dropdown-content{
    display: block;
}
/* 标题栏优化到此 */
导航栏CSS定制代码

页首Html代码

<!-- 创建新的导航栏,内容可更改为你自己的-->
<div id="shwtop" >
    <ul style="margin-left:0px;margin-right: 0px;" class="test11" >
         <div class="dropdown">
            <a href="#" class="dropbtn">博客园管理</a>
            <div class="dropdown-content">
                <!-- <a class="menu" href="这里是你文章或随笔分类的链接地址,自己修改下面同理"> 这里更改下拉具体内容 </a> -->
                <a class="menu" href="https://www.cnblogs.com/"  >1.博客园首页</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/"  >2.我的首页</a>
                <a class="menu" href="https://i-beta.cnblogs.com/posts/edit"  >3.添加新随笔</a>
                <a class="menu" href="https://msg.cnblogs.com/send/%E6%B8%A9%E4%B8%80%E5%A3%B6%E6%B8%85%E9%85%92"  >4.联系博主</a>
                <a class="menu" href="https://i-beta.cnblogs.com/"  >5.博客园后台</a>
            </div>
        </div>

        <div class="dropdown">
            <a href="#" class="dropbtn">全部分类</a>
            <div class="dropdown-content">
                <!-- <a class="menu" href="这里是你文章或随笔分类的链接地址,自己修改下面同理"> 这里更改下拉具体内容 </a> -->
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1541858.html"  >1.APP自动化</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1357115.html"  >2.Jmeter自动化</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1462114.html"  >3.Linux环境搭建</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1092643.html"  >4.Jmeter基础</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1081628.html"  >5.UI自动化(Java)</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1291998.html"  >6.Python</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1085615.html"  >7.接口测试</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1447060.html"  >8.抓包工具</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">APP自动化</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11475812.html"  >1.自动化环境搭建</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11546338.html"  >2.Genymotion模拟器</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11614039.html"  >3.Appium API</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11615628.html"  >4.Appium-Server与Appium-Desktop</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1541858.html"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">Jmeter自动化</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10290315.html"  >1.Jenkins环境搭建</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10462493.html"  >2.jmeter+ant+jenkins环境搭建</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10473996.html"  >3.邮件发送</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10547176.html"  >4.定时构建</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10706234.html"  >5.参数化配置</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10849062.html"  >6.优化测试报告</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1357115.html"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">Linux环境搭建</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10890812.html"  >1.Java+Tomcat配置</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11073195.html"  >2.Jenkins+Gitlab配置</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11073308.html"  >3.Jmeter+Ant配置</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11073507.html"  >4.综合实践</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1462114.html"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">Jmeter基础</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7640014.html"  >1.Jmeter环境搭建</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7650762.html"  >2.Jmeter关联</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7668258.html"  >3.脚本开发</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10792485.html"  >4.Basic Auth登录</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/12112624.html"  >5.参数化JDBC</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/12109888.html"  >6.参数化CSV</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/12175501.html"  >7.RSA加密</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1092643.html"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">UI自动化(Java)</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7622215.html"  >1.环境搭建</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7623838.html"  >2.驱动+元素定位</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7625800.html"  >3.基本API</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7629039.html"  >4.AutoIT键盘操作</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7544560.html"  >5.TestNG基础</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7554023.html"  >6.TestNG实践</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1081628.html"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">Python</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/9574693.html"  >1.经典排序</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/9656221.html"  >2.截图详解</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/9693865.html"  >3.AutoIT键盘操作</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11679676.html"  >4.Requests实践</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/11593345.html"  >5.Unittest实践</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1291998.html"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">接口测试</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7591751.html"  >1.SoapUI入门</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7615182.html"  >2.Postman基础</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7596342.html"  >3.Postman动态传参</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7601859.html"  >4.Postman高级应用</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7610606.html"  >5.HttpClient介绍</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7617855.html"  >6.HttpClient实践</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1085615.html"  target="_Blank">更多...</a>
            </div>
        </div>


        <div class="dropdown">
            <a href="#" class="dropbtn">抓包工具</a>
            <div class="dropdown-content">
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/7582947.html"  >1.Fiddler基础</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10727178.html"  >2.Fiddler篡改数据</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/10889227.html"  >3.Fiddler小技巧</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/12562448.html"  >4.移动端工具Stream</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/p/12582455.html"  >5.FiddlerMock测试</a>
                <a class="menu" href="https://www.cnblogs.com/hong-fithing/category/1447060.html"  target="_Blank">更多...</a>
            </div>
        </div>
    </ul>
</div>
<!-- 创建新的导航栏,内容可更改为你自己的-->
页首HTML代码

我们来看下效果图,如下所示:

2.添加顶部信息

增加页面顶部信息,代码放到页首HTML中,代码示例如下:

<!-- 添加博客顶部博主信息-->
<p style="text-align: center;font-size:40px;font-family: 'STLiti';margin-bottom:8px;margin-top:25px;opacity: 0.5">欢迎来到温一壶清酒的博客</p>

效果图如下所示:

3.添加顶部公告

增加个顶部公告,添加一幅诗词,是不是增加了点文人雅士的气息,^_^^_^,我们来看代码,将代码增加到页首HTML中即可,如下所示:

<!-- 添加顶部滚动信息(公告)例子:《行路难》-->
<div id="Scroll_info" style="text-align: center;color:red;font-size:13px;padding:5px;opacity: 0.5">。
《行路难》李白
金樽清酒斗十千,玉盘珍羞直万钱。
停杯投箸不能食,拔剑四顾心茫然。
欲渡黄河冰塞川,将登太行雪满山。
闲来垂钓碧溪上,忽复乘舟梦日边。
行路难!行路难!多歧路,今安在?
长风破浪会有时,直挂云帆济沧海</div>
<script>
       function func(){
           var tag = document.getElementById('Scroll_info');
           var content = tag.innerText;
           var f = content.charAt(0);
           var l = content.substring(1,content.length);
           var new_content = l + f;
           tag.innerText = new_content;
       }
       setInterval('func()',1600);
</script>
顶部公告

效果图如下所示:

4.添加目录导航

书写博文,就是用于分享并记录自己的成长史。有不错的阅读索引,可以给博文增加不错的好感。目录为两级,为H2、H3,也就是默认编辑器的标题2和标题3格式,Markdown对应##和###,所以只要你以后文章按照这个标题格式写,就能自动生成目录。分享的代码示例已支持三级菜单,目录导航按键的位置,大小,颜色等样式你可以修改代码改变,把代码放到“页面定制CSS代码”框和“页脚HTML代码”框,代码如下:

页面定制CSS代码

/* 定制生成博客目录的CSS样式 */
#uprightsideBar{
    font-size:16px;
    font-family:Arial, Helvetica, sans-serif;
    text-align:left;
    position:fixed;
    /*
    将div的位置固定到距离top:150px,right:0px的位置,
    这样div就会处在最右边的位置,距离顶部150px,
    当然这两个值你可以自己改。
    */
    top:150px;
    right:0px;
    width: auto;
    height: auto; 
}
#sideBarTab{
    float:left;
    width:25px; 
    box-shadow: 0 0 8px #877788;
    border:1px solid #00DDC00;
    border-right:none;
    text-align:center;
    background:rgb(72 ,118, 255);
}
#sideBarContents{
    float:left;
    overflow:auto; 
    overflow-x:hidden;!important;
    width:200px;
    min-height:101px;
    max-height:460px;
    border:1px solid #e5e5e5;
    border-right:none; 
    background:#ffffff;
}
#sideBarContents dl{
    margin:0;
    padding:0;
}
#sideBarContents dt{
    margin-top:5px;
    margin-left:5px;
}
#sideBarContents dd, dt,ds {
    cursor: pointer;
}
#sideBarContents dd:hover, dt:hover,ds:hover {
    color:#A7995A;
}
#sideBarContents dd{
    margin-left:20px;
}
页面定制CSS代码

页脚Html代码

<script type="text/javascript">
/*  
    这段代码按H2、H3格式生成两级菜单
    写博客按H2、H3格式写,不然生成不了
    Markdown写作按##、###两级目录写
    当然你也可以改写代码成三级菜单
*/
var BlogDirectory = {
    /* 获取元素位置,距浏览器左边界的距离(left)和距浏览器上边界的距离(top)*/
    getElementPosition:function (ele) {
        var topPosition = 0;
        var leftPosition = 0;
        while (ele){
            topPosition += ele.offsetTop;
            leftPosition += ele.offsetLeft;
            ele = ele.offsetParent;
        }
        return {top:topPosition, left:leftPosition};
    },
    /*获取滚动条当前位置 */
    getScrollBarPosition:function () {
        var scrollBarPosition = document.body.scrollTop || document.documentElement.scrollTop;
        return  scrollBarPosition;
    },
    /* 移动滚动条,finalPos 为目的位置,internal 为移动速度 */
    moveScrollBar:function(finalpos, interval) {
        //若不支持此方法,则退出
        if(!window.scrollTo) {
            return false;
        }
        
        //窗体滚动时,禁用鼠标滚轮
        window.onmousewheel = function(){
            return false;
        };
        
        //清除计时
        if (document.body.movement) {
            clearTimeout(document.body.movement);
        }
        
        //获取滚动条当前位置
        var currentpos =BlogDirectory.getScrollBarPosition();

        var dist = 0;
        //到达预定位置,则解禁鼠标滚轮,并退出
        if (currentpos == finalpos) {
            window.onmousewheel = function(){
                return true;
            }
            return true;
        }
        //未到达,则计算下一步所要移动的距离
        if (currentpos < finalpos) {
            dist = Math.ceil((finalpos - currentpos)/10);
            currentpos += dist;
        }
        if (currentpos > finalpos) {
            dist = Math.ceil((currentpos - finalpos)/10);
            currentpos -= dist;
        }

        var scrTop = BlogDirectory.getScrollBarPosition();//获取滚动条当前位置
        window.scrollTo(0, currentpos);//移动窗口
        if(BlogDirectory.getScrollBarPosition() == scrTop)//若已到底部,则解禁鼠标滚轮,并退出
        {
            window.onmousewheel = function(){
                return true;
            }
            return true;
        }

        //进行下一步移动
        var repeat = "BlogDirectory.moveScrollBar(" + finalpos + "," + interval + ")";
        document.body.movement = setTimeout(repeat, interval);
    },

    htmlDecode:function (text){
        var temp = document.createElement("div");
        temp.innerHTML = text;
        var output = temp.innerText || temp.textContent;
        temp = null;
        return output;
    },
    
    /*
    创建博客目录,id表示包含博文正文的 div 容器的 id,
    mt 和 st 分别表示主标题和次级标题的标签名称(如 H2、H3,大写或小写都可以!),
    interval 表示移动的速度
    */
    createBlogDirectory:function (id, mt, st, newdist, interval){
        //获取博文正文div容器
        var elem = document.getElementById(id);
        if(!elem) return false;
        //获取div中所有元素结点
        var nodes = elem.getElementsByTagName("*");
        //创建博客目录的div容器
        var divSideBar = document.createElement('DIV');
        divSideBar.className = 'uprightsideBar';
        divSideBar.setAttribute('id', 'uprightsideBar');
        var divSideBarTab = document.createElement('DIV');
        divSideBarTab.setAttribute('id', 'sideBarTab');
        divSideBar.appendChild(divSideBarTab);
        var h2 = document.createElement('H2');
        divSideBarTab.appendChild(h2);
        var txt = document.createTextNode('目录导航');
        h2.appendChild(txt);
        var divSideBarContents = document.createElement('DIV');
        divSideBarContents.style.display = 'none';
        divSideBarContents.setAttribute('id', 'sideBarContents');
        divSideBar.appendChild(divSideBarContents);
        //创建自定义列表
        var dlist = document.createElement("dl");
        divSideBarContents.appendChild(dlist);
        var num = 0;//统计找到的mt和st
        mt = mt.toUpperCase();//转化成大写
        st = st.toUpperCase();//转化成大写
        newdist = newdist.toUpperCase();//转化成大写
        //遍历所有元素结点
        for(var i=0; i<nodes.length; i++)
        {
            if(nodes[i].nodeName == mt|| nodes[i].nodeName == st || nodes[i].nodeName == newdist)
            {
                //获取标题文本
                var nodetext = nodes[i].innerHTML.replace(/<\/?[^>]+>/g,"");//innerHTML里面的内容可能有HTML标签,所以用正则表达式去除HTML的标签
                nodetext = nodetext.replace(/ /ig, "");//替换掉所有的
                nodetext = BlogDirectory.htmlDecode(nodetext);
                //插入锚
                nodes[i].setAttribute("id", "blogTitle" + num);
                var item;
                switch(nodes[i].nodeName)
                {
                    case mt:    //若为主标题
                        item = document.createElement("dt");
                        break;
                    case st:    //若为子标题
                        item = document.createElement("dd");
                        break;
                    case newdist:    //若为子标题
                        item = document.createElement("ds");
                        break;
                }

                //创建锚链接
                var itemtext = document.createTextNode(nodetext);
                item.appendChild(itemtext);
                item.setAttribute("name", num);
                //添加鼠标点击触发函数
                item.onclick = function(){        
                var pos = BlogDirectory.getElementPosition(document.getElementById("blogTitle" + this.getAttribute("name")));
                    if(!BlogDirectory.moveScrollBar(pos.top, interval)) return false;
                };
                //将自定义表项加入自定义列表中
                dlist.appendChild(item);
                num++;
            }
        }

        if(num == 0) return false;
        /* 鼠标进入时的事件处理 */
        divSideBarTab.onmouseenter = function(){
            divSideBarContents.style.display = 'block';
        }
        /* 鼠标离开时的事件处理 */
        divSideBar.onmouseleave = function() {
            divSideBarContents.style.display = 'none';
        }

        document.body.appendChild(divSideBar);
    }

};

window.onload=function(){
    /* 页面加载完成之后生成博客目录 */
    BlogDirectory.createBlogDirectory("cnblogs_post_body","h2","h3","h4",20);
    
    //为右下角推荐推荐区域添加关注按钮
    $('#div_digg').prepend('<div style="padding-bottom: 5px"><span class="icon_favorite" style="padding-top: 2px"></span><a onclick="follow(\'ab04813a-468b-4ddf-dd4b-08d4ef52ecb5\');" href="javascript:void(0);" style="font-weight: bold; padding-left:5px;">关注下博主哟</a> </div>');
}
</script>
页脚HTML代码

效果图如下所示:

5.美化推荐功能

平时自己写的博文,被博友们,自然是一件喜悦的事情,此处优化了下按钮的位置,示例代码如下所示,代码写到页面定制CSS中。

页面定制CSS代码

/* 点赞与反对优化 */
#div_digg {
    padding: 0px;
    position: fixed;
    _position: absolute;
    bottom: 20px;
    right: -28px;
    border: 1px solid #D9DBE1;
    background-color: #FFFFFF;
    filter: alpha(Opacity=80);
    -moz-opacity: 1;
    opacity: 1;
    text-align: center;
}
.icon_favorite {
    background: transparent url('http://files.cnblogs.com/files/jackson0714/kj.gif') no-repeat 0 0;
    padding-left: 16px;
}

/* 隐藏反对入口 */
.buryit {display:none;}

/* 配置点赞按钮居中 */
.diggit{
    float:left;
    margin-left:40px;
    width:46px;
    height:52px;
    text-align:center;
    cursor:pointer;
    margin-top:2px;
    padding-top:5px;
}
页面定制CSS代码

效果图如下所示:

6.添加快速返回

添加快速返回顶部的功能按键,使其能够在文章任意文字快速返回文章顶部,把代码分别粘贴到“页面定制CSS代码”框和“页首HTML代码”框,和上面一样修改代码,可以调整按键的位置,大小等,代码如下:

页面定制CSS代码

/* 定制返回顶部按键 */
#toTop {
    background: url(https://files-cdn.cnblogs.com/files/hong-fithing/timg_top.bmp) no-repeat 0px top;
    width: 65px;
    height: 65px;
    overflow: hidden;
    position: fixed;
    right: 140px;
    bottom: 20px;
    cursor: pointer;
    padding: 0px;
    margin:10px;
}

页首HTML代码

<!-- 指定返回顶部位置#shwtop -->
<a href="#shwtop"><div id="toTop" style="zoom:0;"></div></a>

效果图如下:

7.添加打赏功能

为博客添加一个打赏功能,如果读者觉得你的文章对他有帮助,他可以通过这个按键来打赏你。当然,要用这个插件功能,首先你得配置以下参数。代码list[]qrImg: 'https://files-cdn.cnblogs.com/files/hong-fithing/zhifubao_100_100.bmp'里的支付宝或者微信二维码的图片位置,你要修改成你自己的。【不过不修改,我也不介意的,哈哈哈哈】

在配置打赏功能时,需要先到支付宝或者微信客户端生成一个二维码,然后保存到手机,上传到电脑,再上传到你的博客相册中,然后获得图片源链接。

这里需要注意的是,静态图片,不要过大,最好是设置下图片的大小再上传到博客文件中。

参数设置

1.修改支付宝和微信二维码链接;

2.修改top:  '40%' :这一项可以改变按键在屏幕的位置,调到你屏幕的合适位置,这里可以用百分比%,也可以用像素px来指定;

3.修改id:9这一项修改颜色,1~9代表不同的9种颜色,可以尝试修改;

4.修改type:'dashang'这一项是修改显示文字的。有两种显示,一种是打赏(dashang),一种是赞助(zanzhu)。

贡献该插件作者的github地址是:https://github.com/greedying/tctip

打赏功能的代码写在页脚HTML代码中,代码如下所示:

<!-- 添加打赏功能按键  -->
<script src="https://static.tctip.com/tctip-1.0.2.min.js"></script>
<script>  
  new tctip({
    top: '40%',
    button: {
      id: 9,
      type: 'dashang',
    },
    list: [
      {
        type: 'alipay',
        qrImg: 'https://files-cdn.cnblogs.com/files/hong-fithing/zhifubao_100_100.bmp'
      }, 
      {
        type: 'wechat',
        qrImg: 'https://files-cdn.cnblogs.com/files/hong-fithing/weixin_100_100.bmp'
      }
    ]
  }).init()
</script>
打赏功能

效果图如下:

8.添加github地址

在博客页面中添加Github图标,可以快速链接到你的github或者其他网址。图标的样式可以自己修改,代码放在“页脚HTML代码”框中,代码如下:

页脚HTML代码

<!-- 博客页面脚添加Github链接或其他链接 -->
<!-- 页面左上角 -->
<a href="https://www.jianshu.com/u/518462f09fa6" 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>
<!-- 页面右上角 -->
<a href="" 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>
github地址

效果图如下:

9.添加个性时钟

在博客左侧栏增加个时钟,丰富下页面,代码分部放到页面定制CSS博客侧边栏公告中,代码如下所示:

页面定制CSS代码

/* 定制公告栏时钟位置 */
#clockdiv {
    /* left, center, right */
    text-align: center;
}

博客侧边栏公告代码

<!-- 添加公告栏时钟 -->
<div id="clockdiv">
    <canvas id="dom" width="120" height="120">时钟canvas</canvas>
</div>
<script type="text/javascript" src="https://files.cnblogs.com/files/shwee/clock.js"></script>

效果图如下:

10.添加访客来源

在添加访客来源功能时,好多都是介绍使用Flag Counter这个插件,网址是:http://s11.flagcounter.com/more/Fe64/,但我操作了下,似乎是不生效,不知是我配置问题还是如何。当配置不生效的情况下,我就换了种方式。使用该网站来统计:https://www.bfcounter.vip/,按网址提供的步骤操作即可。将代码放到博客侧边栏公告代码中,如下所示:

<!-- 访问地区来源统计 -->
<h3>访客来源</h3>
<a href="https://www.bfcounter.vip/"><img src="https://www.bfcounter.vip/generatepic?userid=656a7624-6c20-45c7-ac21-1b1c6fa67d20" alt="Page Counter" border="0"></a>

效果图如下:

11.添加点击特效

添加鼠标点击心形特效,代码放到博客侧边栏公告中,代码示例如下:

博客侧边栏公告代码

<script type="text/javascript">
/* 点击出现爱心特效*/
(function(window,document,undefined){
        var hearts = [];
        window.requestAnimationFrame = (function(){
                return window.requestAnimationFrame || 
                           window.webkitRequestAnimationFrame ||
                           window.mozRequestAnimationFrame ||
                           window.oRequestAnimationFrame ||
                           window.msRequestAnimationFrame ||
                           function (callback){
                                   setTimeout(callback,1000/60);
                           }
        })();
        init();
        function init(){
                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;}");
                attachEvent();
                gameloop();
        }
        function gameloop(){
                for(var i=0;i<hearts.length;i++){
                    if(hearts[i].alpha <=0){
                            document.body.removeChild(hearts[i].el);
                            hearts.splice(i,1);
                            continue;
                    }
                    hearts[i].y--;
                    hearts[i].scale += 0.004;
                    hearts[i].alpha -= 0.013;
                    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;
            }
            requestAnimationFrame(gameloop);
        }
        function attachEvent(){
                var old = typeof window.onclick==="function" && window.onclick;
                window.onclick = function(event){
                        old && old();
                        createHeart(event);
                }
        }
        function createHeart(event){
            var d = document.createElement("div");
            d.className = "heart";
            hearts.push({
                    el : d,
                    x : event.clientX - 5,
                    y : event.clientY - 5,
                    scale : 1,
                    alpha : 1,
                    color : randomColor()
            });
            document.body.appendChild(d);
    }
    function css(css){
            var style = document.createElement("style");
                style.type="text/css";
                try{
                    style.appendChild(document.createTextNode(css));
                }catch(ex){
                    style.styleSheet.cssText = css;
                }
                document.getElementsByTagName('head')[0].appendChild(style);
    }
        function randomColor(){
                return "rgb("+(~~(Math.random()*255))+","+(~~(Math.random()*255))+","+(~~(Math.random()*255))+")";
        }
})(window,document);

</script>
心形特效

效果图如下:

12.添加个性签名

添加个性签名,增加样式优化,页面定制CSS代码示例如下:

/* 设置签名格式 定制css样式 */
#MySignature {
    display: none;
    background-color: #B2E866;
    border-radius: 10px;
    box-shadow: 1px 1px 1px #6B6B6B;
    padding: 10px;
    line-height: 1.5;
    text-shadow: 1px 1px 1px #FFF;
    font-size: 16px;
    font-family: 'Microsoft Yahei';
}

样式添加好了,那就到博客签名中,添加签名内容,点击博客园中的管理>博客签名按钮,如下:

添加签名内容,如下所示:

<div>作者:<a href="https://www.cnblogs.com/hong-fithing/">温一壶清酒</a></div>
<div>出处:<a href="https://www.cnblogs.com/hong-fithing/">https://www.cnblogs.com/hong-fithing/
</a></div>
<div>本文仅代表作者观点,系作者@温一壶清酒发表。<br />文中书写有误之处,欢迎批评指正。<br />欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。</div>
<p>-------------------------------------------</p>
<p>座右铭:发上等愿,结中等缘,享下等福;
择高处立,寻平处住,向宽处行。</p>
<p>如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个<span style="color: #F00000; font-size: 18px"> [推荐]</span>哦,博主在此感谢!</p>
<p></p>
<p>你的打赏,是对博主最大的鼓励;如果你心情无比愉悦,也是可以扫码打赏博主的,哈哈哈^_^O(∩_∩)O哈哈~</p>
<div align="left">
<img src="https://files-cdn.cnblogs.com/files/hong-fithing/weixin_100_100.bmp">
<img src="https://files-cdn.cnblogs.com/files/hong-fithing/zhifubao_100_100.bmp">
</div>

效果图如下所示:

13.添加标题样式

博文中,都会有不同的标题,但标题又如何来区分呢,增加如下样式,那便一目了然了,也可以自定义修改,看个人喜好,示例代码如下:

页面定制CSS代码

/* 定制生成博客标题样式 */
#cnblogs_post_body
{
    color: black;      
    font: 0.875em/1.5em "微软雅黑" , "PTSans" , "Arial" ,sans-serif;
    font-size: 15px;
}
#cnblogs_post_body h1    {
    background:#169fe6;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 22pt;
    font-weight: bold;
    height: 25px;
    line-height: 25px;
    margin: 18px 0 !important;
    padding: 8px 0 5px 5px;
    text-shadow: 2px 2px 3px #222222;
}
#cnblogs_post_body h2    {
    background: #006699;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 18px;
    font-weight: bold;
    height: 25px;
    line-height: 25px;
    margin: 18px 0 !important;
    padding: 8px 0 5px 5px;
    text-shadow: 2px 2px 3px #222222;
}
#cnblogs_post_body h3    {
    background: #87CEFA;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #AFEEEE, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 16px;
    font-weight: bold;
    height: 25px;
    line-height: 25px;
    margin: 18px 0 !important;
    padding: 8px 0 5px 5px;
    text-shadow: 2px 2px 3px #222222;
}
#cnblogs_post_body h4{
    background: #2B6600;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 14px;
    font-weight: bold;
    height: 24px;
    line-height: 23px;
    margin: 12px 0 !important;
    padding: 5px 0 5px 10px;
    text-shadow: 2px 2px 3px #222222;
}
#cnblogs_post_body h5{
    background: #778899;
    border-radius: 6px 6px 6px 6px;
    box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
    color: #FFFFFF;
    font-family: "微软雅黑" , "宋体" , "黑体" ,Arial;
    font-size: 12px;
    font-weight: bold;
    height: 23px;
    line-height: 22px;
    margin: 12px 0 !important;
    padding: 5px 0 5px 10px;
    text-shadow: 2px 2px 3px #222222;
}
标题样式代码

效果图如下:

14.隐藏默认内容

既然是自定义博客内容,那自然有些内容是不想要的,那该如何处理呢?不想展示在页面中,那直接隐藏掉即可,代码写在页面定制CSS中,示例代码如下:

页面定制CSS代码

/* 隐藏导航栏里的订阅 */
#leftmenu ul li a#blog_nav_rss{display: none;}
/* 隐藏导航栏里的订阅图片 */
#leftmenu ul li a#blog_nav_rss_image{display: none;}
/* 隐藏导航栏里的标题 */
/*#leftmenu h3{display: none;}*/
/* 隐藏导航栏里的博客园入口 */
#leftmenu ul li a#blog_nav_sitehome{display: none;}
/* 隐藏导航栏里的个人博客入口 */
#leftmenu ul li a#blog_nav_myhome{display: none;}
/* 隐藏导航栏里的新随笔入口 */
#leftmenu ul li a#blog_nav_newpost{display: none;}
/* 隐藏导航栏里的联系入口 */
#leftmenu ul li a#blog_nav_contact{display: none;}
/* 隐藏导航栏里的管理入口 */
#leftmenu ul li a#blog_nav_admin{display: none;}
/* 隐藏搜索入口 */
#sidebar_search{display: none;}
/* 隐藏常用链接入口 */
#sidebar_shortcut{display: none;}

将不想要的内容隐藏后,页面会觉得更简洁。

问题

图片过大

增加了打赏功能,加载图片会出现失败的情况,访问静态图片,提示错误如下所示:

{"success":false,"message":"该文件已超过当日下载流量(200MB)的下载限制"}

解决该问题,就是将图片变小一些,这里需要注意。

打赏功能不展示

配置了打赏功能,但对应功能没有展示,百度查访了一番,有网友解答道,因为浏览器为了安全起见,默认是不允许在HTTPS里面引用HTTP资源的。

解决办法:

将我们后台代码中<script src="//static.tctip.com/tctip-1.0.2.min.js"></script>

替换成<script src="https://static.tctip.com/tctip-1.0.2.min.js"></script>

再次访问页面,打赏功能就正常展示了。

以上内容就是我自己在优化博客页面的总结了,也是感谢各位大佬的分享,让我东拼西凑,整合成一份完美的优化。

posted @ 2020-04-21 13:26  温一壶清酒  阅读(1400)  评论(9编辑  收藏  举报