欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

博客园美化大全

程序员文章站 2023-11-22 21:39:46
1.1、自动生成目录 效果如下: (1)页脚js代码 首先得有js权限 (2)页面定制css代码 1.2.增加返回顶部按钮 (1)页面定制css代码 (2)页首html代码 1.3.爱心特效(鼠标点击页面) 鼠标点击页面效果: 把下面代码复制到公告栏里面 1.4.公告栏时钟 公告里面 1.5.公告栏 ......

1.1、自动生成目录

效果如下:

博客园美化大全

 

(1)页脚js代码

首先得有js权限

博客园美化大全
<script type="text/javascript">
/*
    功能:生成博客目录的js工具
    测试:ie8,火狐,google测试通过
    zhang_derek
    2018-01-03
*/
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, 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();//转化成大写
        //遍历所有元素结点
        for(var i=0; i<nodes.length; i++)
        {
            if(nodes[i].nodename == mt|| nodes[i].nodename == st)    
            {
                //获取标题文本
                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;
                }
                
                //创建锚链接
                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",20);
}
</script>
博客园美化大全

(2)页面定制css代码

博客园美化大全
/*生成博客目录的css*/
#uprightsidebar{
    font-size:14px;
    font-family:arial, helvetica, sans-serif;
    text-align:left;
    position:fixed;/*将div的位置固定到距离top:50px,right:0px的位置,这样div就会处在最右边的位置,距离顶部50px*/
    top:400px;
    right:53px;
    width: auto;
    height: auto; 
    
    
}
#sidebartab{
    float:left;
    width:30px; 
    border:1px solid #e5e5e5;
    border-right:none;
    text-align:center;
    background:rgb(238, 130, 238);
}

#sidebarcontents{
    float:left;
    overflow:auto; 
    overflow-x:hidden;!important;
    width:200px;
    min-height:108px;
    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 {
    cursor: pointer;
}

#sidebarcontents dd:hover, dt:hover {
    color:#a7995a;
}
#sidebarcontents dd{
    margin-left:20px;
}
博客园美化大全

 

1.2.增加返回顶部按钮

(1)页面定制css代码

博客园美化大全
#back-to-top {
    background-color: #00cd00;
    bottom: 0;
    box-shadow: 0 0 6px #00cd00;
    color: #444444;
    padding: 10px 10px;
    position: fixed;
    right: 50px;
    cursor: pointer;
}
博客园美化大全

(2)页首html代码

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

 

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

鼠标点击页面效果:

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

博客园美化大全
<!-- 爱心特效 -->
<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>
博客园美化大全

 

1.4.公告栏时钟

公告里面

博客园美化大全
<div id="mytime">
        <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">
            <param name="allowscriptaccess" value="always">
            <param name="movie" value="http://chabudai.sakura.ne.jp/blogparts/honehoneclock/honehone_clock_wh.swf">
            <param name="quality" value="high">
            <param name="bgcolor" value="#ffffff">
            <param name="wmode" value="transparent">
            <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">
        </object>
    </div>
博客园美化大全

 

1.5.公告栏里面添加信息

公告里面

  • 图片路径:可以把图片上传到你的博客相册里面,然后把图片地址复制过来就可以
博客园美化大全
<p class="gonggao">&nbsp<a style="color: blue;font-weight: bold;" href="http://www.cnblogs.com/derek1184405959/p/8579428.html">我的博客文章(目录)</a></p>
<p class="qq">&nbsp;写自己想要的一些信息</p>

&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代码

博客园美化大全
.qq{
    color:red;
    font-size:15px;
    margin:8px;
   font-weight: 500;
}
.gonggao{
    margin:8px;
 font-size:16px;
    color:blue;
}
博客园美化大全

 

1.6.添加github图标

页首html代码

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

博客园美化大全
<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>



<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代码

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

(2)页面定制css样式

博客园美化大全
#divexpandviewarea{
    position: fixed;
    color: white;
   
    padding: 10px 10px;
    left: 0px;
    top: 547px;
    cursor: pointer;
    opacity: 0.9;
    background-color: #68228b;
}
 
#divcollapseviewarea{
    position: fixed;
    color: white;
    
    padding: 10px 10px;
    left: 0px;
    top: 586px;
    cursor: pointer;
    opacity: 0.9;
    background-color: #68228b;
}
博客园美化大全

 

1.8.设置签名格式

效果如下:

博客园美化大全

页面定制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';
}
博客园美化大全

 

1.9.设置随笔分类间距

左侧随笔分类之间间距

页面定制css样式

博客园美化大全
/* 左侧最新随笔 */
#catlist_linklist_0_link_0{
    
}
#catlist_linklist_0_link_1{
   
margin-top:10px;
}
#catlist_linklist_0_link_2{
   
    margin-top:10px;
}
#catlist_linklist_0_link_3{
 
margin-top:10px;

}
#catlist_linklist_0_link_4{
    
margin-top:10px;

}
#catlist_linklist_0_link_5{
    
margin-top:10px;

}
#catlist_linklist_0_link_6{
    
margin-top:10px;

}
#catlist_linklist_0_link_7{
    
margin-top:10px;

}
#catlist_linklist_0_link_8{
    
margin-top:10px;

}
博客园美化大全

 

1.10.添加分享功能

效果如下:

博客园美化大全

 

公告栏里面

博客园美化大全
<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代码

博客园美化大全
<div id="i1" style="color:red;font-size:13px;padding:5px;">大江东去,浪淘尽,千古风流人物。故垒西边,人道是,三国周郎赤壁。乱石穿空,惊涛拍岸,卷起千堆雪。*如画,一时多少豪杰。遥想公瑾当年,小乔初嫁了,雄姿英发。羽扇纶巾,谈笑间,樯橹灰飞烟灭。故国神游,多情应笑我,早生华发。人生如梦,一尊还酹江月。</div>
    <script>
       function func(){
           var tag = document.getelementbyid('i1');
           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>
博客园美化大全

 

1.12.推荐和反对

页面定制css

博客园美化大全
/*推荐和反对*/
#div_digg {
    padding: 10px;
    position: fixed;
    _position: absolute;
    z-index: 1000;
    bottom: 20px;
    right: 0;
    _right: 17px;
    border: 1px solid #d9dbe1;
    background-color: #ffffff;
    filter: alpha(opacity=80);
    -moz-opacity: 1;
    opacity: 1;
}

.icon_favorite {
    background: transparent url('http://files.cnblogs.com/files/jackson0714/kj.gif') no-repeat 0 0;
    padding-left: 16px;
}
博客园美化大全