【*狂魔】手把手教你用JS给博客动态增加目录 - 超级懒人版

时间:2020-12-14 07:19:29

动态显示目录的作用

不用每次写博客的时候繁琐的人工整理目录,又可以动态浮动在右下角,方便快速跳到感兴趣的位置同时也可以快速的对文章内容有一个大概的了解。

实现原理

首先根据个人喜好,我习惯了用 h1 来做分类。所以本篇内容也主要是针对h1来提取目录。

如何提取出来h1呢?

【*狂魔】手把手教你用JS给博客动态增加目录 - 超级懒人版

先来看这张图,以猎豹浏览器为例:

首先在博客内容第一行点击鼠标右键,然后选择检查。这时会弹出右边的框,直接定位到我的h1标签,就这么简单的找到了它的父级 cnblogs_post_body 。

然后使用 jquery 选择器 来获取到这些h1,对jquery选择器不熟的直接跳这个链接温习一下:http://www.w3school.com.cn/jquery/jquery_ref_selectors.asp

$('#cnblogs_post_body h1')

就这么简单的一个括号就完成了对 h1 的提取。

在遍历所有的h1,取出内容之前,我们需要一个目录的容器。

$('#cnblogs_post_body').append('<div id="blog_catalog" class="blog_catalog"><ul><li><a id="blog_catalog_close" class="blog_catalog_close">>折叠目录</a></li></ul></div>');

这句简单解释就是在博客内容最末尾插入了一个 div,里面包含ul和一个默认的li 用于折叠目录。

接下来就要提取h1的内容了,但在这个过程中我们还要做一件事,就是自动给h1增加一个id,作为一个标准的懒人,我肯定连h1的id都不想写的,自动生成神马的最好了。

var id = ;
$('#cnblogs_post_body h1').each(function(){
$(this).attr('id','blog_catalog_id_'+id);
$('#blog_catalog ul').append('<li><a href="#blog_catalog_id_'+id+'">'+$(this).text()+'</a></li>');
id++;
});

有了折叠,当然少不了展开。

$('#cnblogs_post_body').append('<div id="blog_catalog_open" class="blog_catalog_open">展开目录</div>');

最后一步,让展开目录和折叠目录联动起来

$('#blog_catalog_open').click(function(){
$('#blog_catalog').show();
$('#blog_catalog_open').hide();
}); $('#blog_catalog_close').click(function(){
$('#blog_catalog').hide();
$('#blog_catalog_open').show();
});

整个制作过程其实并不复杂,还有一些css样式应用上就完工了。

不管原理,我想直接用

怎么自定义皮肤我就不多说了,一抓一大把。下面直接给你们代码。

css:

.blog_catalog {
display: none;
width: auto;
height: auto;
float: right;
position: fixed;
right: 180px;
bottom: 200px;
z-index: ;
background-color: #fff;
font-size: 12px;
margin: 10px ;
padding: 5px;
text-align: center;
border: 3px solid #55895b;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
-moz-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
} .blog_catalog > li > a {
background-color: #;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(, , )),to(rgb(, , )));
background-image: -webkit-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -moz-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -o-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -ms-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: linear-gradient(top, rgb(, , ), rgb(, , ));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=,StartColorStr='#727a86', EndColorStr='#505864');
-webkit-box-shadow: inset 0px 1px 0px 0px #878e98;
-moz-box-shadow: inset 0px 1px 0px 0px #878e98;
box-shadow: inset 0px 1px 0px 0px #878e98;
width: %;
height: .75em;
line-height: .75em;
text-indent: .75em;
display: block;
position: relative;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: ;
color: #fff;
text-shadow: 0px 1px 0px rgba(,,,.);
} .blog_catalog ul li a {
background: #fff;
border-bottom: 1px solid #efeff0;
width: %;
height: .75em;
line-height: .75em;
display: block;
position: relative;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: .923em;
font-weight: ;
color: #878d95;
} .blog_catalog ul li a:hover {
cursor: pointer;
} .blog_catalog > li > a:hover, .blog_catalog > li > a.active, .blog_catalog > li:target > a; /*add this*/ {
background-color: #35afe3;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(, , )),to(rgb(, , )));
background-image: -webkit-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -moz-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -o-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -ms-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: linear-gradient(top, rgb(, , ), rgb(, , ));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=,StartColorStr='#45c7eb', EndColorStr='#2698db');
border-bottom: 1px solid #103c56;
-webkit-box-shadow: inset 0px 1px 0px 0px #6ad2ef;
-moz-box-shadow: inset 0px 1px 0px 0px #6ad2ef;
box-shadow: inset 0px 1px 0px 0px #6ad2ef;
} .blog_catalog > li > a.active {
border-bottom: 1px solid #1a638f;
} .blog_catalog > li > a:before {
content: '';
background-image: url(../images/sprite.png);
background-repeat: no-repeat;
font-size: 36px;
height: 1em;
width: 1em;
position: absolute;
left: ;
top: %;
margin: -.5em ;
} .item1 > a:before {
background-position: ;
} .item2 > a:before {
background-position: -38px ;
} .item3 > a:before {
background-position: -38px;
} .item4 > a:before {
background-position: -38px -38px;
} .item5 > a:before {
background-position: -76px ;
} .blog_catalog > li > a span {
font-size: .857em;
display: inline-block;
position: absolute;
right: 1em;
top: %;
background: #48515c;
line-height: 1em;
height: 1em;
padding: .4em .6em;
margin: -.8em ;
color: #fff;
text-indent: ;
text-align: center;
-webkit-border-radius: .769em;
-moz-border-radius: .769em;
border-radius: .769em;
-webkit-box-shadow: inset 0px 1px 3px 0px rgba(, , , .), 0px 1px 0px 0px rgba(, , , .);
-moz-box-shadow: inset 0px 1px 3px 0px rgba(, , , .), 0px 1px 0px 0px rgba(, , , .);
box-shadow: inset 0px 1px 3px 0px rgba(, , , .), 0px 1px 0px 0px rgba(, , , .);
text-shadow: 0px 1px 0px rgba(,,,.);
font-weight: ;
} .blog_catalog > li > a:hover span,
.blog_catalog > li a.active span,
.blog_catalog > li:target > a span /*add this*/ {
background: #2173a1;
} .blog_catalog > li > ul li a:before {
font-size: 8px;
color: #bcbcbf;
position: absolute;
width: 1em;
height: 1em;
top: ;
left: -.7em;
} .blog_catalog > li > ul li:hover a,
.blog_catalog > li > ul li:hover a span,
.blog_catalog > li > ul li:hover a:before {
color: #32373D;
} .blog_catalog ul > li > a span {
font-size: .857em;
display: inline-block;
position: absolute;
right: 1em;
top: %;
/ background: #fff;
border: 1px solid #d0d0d3;
line-height: 1em;
height: 1em;
padding: .4em .7em;
margin: -.9em ;
color: #878d95;
text-indent: ;
text-align: center;
-webkit-border-radius: .769em;
-moz-border-radius: 769em;
border-radius: 769em;
text-shadow: 0px 0px 0px rgba(,,,.));
} /*additional*/ .blog_catalog > li > ul {
height: ;
overflow: hidden;
opacity: ;
filter: alpha(opacity=); /* IE6-IE8 */
-webkit-transition: opacity .9s ease-in-out;
-moz-transition: opacity .9s ease-in-out;
-o-transition: opacity .9s ease-in-out;
-ms-transition: opacity .9s ease-in-out;
transition: opacity .9s ease-in-out;
} .blog_catalog > li:target > ul {
height: auto; /*using auto nullifies the height transitions, but it makes things flexible which is more important*/
border-bottom: 1px solid #51555a;
opacity: ;
filter: alpha(opacity=); /* IE6-IE8 */
} #cnblogs_post_body ul li {
list-style-type: none;
margin-left: -30px;
} .blog_catalog_open {
width: auto;
height: auto;
float: right;
position: fixed;
right: 180px;
bottom: 200px;
z-index: ;
background-color: #fff;
font-size: 12px;
width: 125px;
margin: 10px ;
padding: 5px;
text-align: center;
border: 3px solid #55895b;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
-moz-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
cursor: pointer;
}

js:

$('#cnblogs_post_body').append('<div id="blog_catalog_open" class="blog_catalog_open">展开目录</div>');
$('#cnblogs_post_body').append('<div id="blog_catalog" class="blog_catalog"><ul><li><a id="blog_catalog_close" class="blog_catalog_close">>折叠目录</a></li></ul></div>'); var id = ;
$('#cnblogs_post_body h1').each(function(){
$(this).attr('id','blog_catalog_id_'+id);
$('#blog_catalog ul').append('<li><a href="#blog_catalog_id_'+id+'">'+$(this).text()+'</a></li>');
id++;
}); $('#blog_catalog_open').click(function(){
$('#blog_catalog').show();
$('#blog_catalog_open').hide();
}); $('#blog_catalog_close').click(function(){
$('#blog_catalog').hide();
$('#blog_catalog_open').show();
});

如何使用

<h1>你可以随意设置你的标题</h1>

没错,就是这么简单,其他什么都不需要。

我不只要用目录,我还要完整皮肤

先声明,我这套皮肤是从别人那扒下来的一个雏形然后自己再改了不少地方。但是从哪里弄来的,忘了。。。很尴尬。

具体设置皮肤的也是一抓一大把就不多说了,上干货。

1.博客皮肤 选择 Custom

2.页面定制css代码

@charset "utf-8";
/* CSS Document */
/* By rhinoc.cnblogs.com*/ /*第一部分*/
#EntryTag {
margin-top: 20px;
font-size: 9pt;
color: gray;
} .topicListFooter {
text-align: right;
margin-right: 10px;
margin-top: 10px;
} #divRefreshComments {
text-align: right;
margin-right: 10px;
margin-bottom: 5px;
font-size: 9pt;
} /*全局样式*/
{
margin: ;
padding: ;
} html {
height: %;
} body {
background-image: url(http://images0.cnblogs.com/blog2015/618672/201508/201613472223856.png);
background-repeat: repeat;
font-family: 'Lucida Console',Georgia,'Microsoft YaHei',Microsoft YaHei;
\5B8B\4F53, sans-serif;
font: 'Lucida Console',Georgia,'Microsoft YaHei',Microsoft YaHei;
font-size: .5px;
min-height: %;
} table {
border-collapse: collapse;
border-spacing: ;
} fieldset, img {
border: ;
} ul {
word-break: break-all;
} li {
list-style: none;
} h1, h2, h3, h4, h5, h6 {
font-size: %;
font-weight: normal;
} a {
outline: none;
color: #21759b;
} address, cite, dfn, em, var {
font-style: normal;
} code, kbd, pre, samp, tt {
font-family: "Courier New", Courier,Microsoft Yahei, monospace;
} .clear {
clear: both;
} /*第三部分*/
/*home和头部*/
#home {
margin: auto;
width: %;
min-width: 1000px;
background-color: #fff;
padding: 30px;
margin-top: 50px;
margin-bottom: 50px;
box-shadow: 0px 1px 10px #;
-moz-box-shadow: 0px 1px 10px #;
-web-kit-shadow: 0px 1px 10px #;
} #header {
padding-bottom: 5px;
margin-top: 20px;
} #blogTitle {
height: 50px;
clear: both;
font-family: Georgia,Serif;
} #InkBlogLogo {
display: none;
} /*博客名称*/
#blogTitle h1 {
font-size: 28px;
font-weight: bold;
line-height: .2em;
margin-top: 20px;
} #blogTitle h1 a {
color: #;
} #blogTitle h1 a:hover {
color: #21759b;
} #blogTitle h2 {
font-weight: normal;
font-size: .5px;
line-height: .3em;
color: #;
float: left;
margin-left: 2em;
margin-bottom: 2em;
} #blogLogo {
float: right;
} /*导航栏*/
#navigator {
text-decoration: none;
font-size: 14px;
font-family: 'Lucida Console',Georgia,'FZYaoTi',Microsoft YaHei;
\5B8B\4F53, sans-serif;
font: 'Lucida Console',Georgia,'FZYaoTi',Microsoft YaHei;
border-bottom: 1px solid #;
border-top: 1px solid #;
height: 80px;
clear: both;
margin-top: 20px;
} #navList {
width: 1200px;
min-height: 30px;
float: left;
} #navList .border {
height: 28px;
position: absolute;
width: 5px;
left: 0px;
top: 0px;
overflow: hidden;
opacity: ;
background: #F90;
-webkit-transition: .3s all ease;
-moz-transition: .3s all ease;
-ms-transition: .3s all ease;
-o-transition: .3s all ease;
-webkit-transition: .5s left ease;
} #navList li {
float: left;
margin: 0px,40px,0px,0px;
-webkit-transition: .3s all ease;
-moz-transition: .3s all ease;
-ms-transition: .3s all ease;
-o-transition: .3s all ease;
transition: .3s all ease;
overflow: hidden;
position: relative;
} #navList li:hover {
background: #;
box-shadow: 2px 2px 4px rgba(, , , 0.4);
} #navList li:hover .border {
opacity: ;
left: 65px;
} #navList li:hover a {
color: #FFF;
text-shadow: 1px 2px 4px #;
} #navList li:hover .menu {
-webkit-animation-name: shake;
-moz-animation-name: shake;
} .menu {
-webkit-animation: .5s .2s ease both;
-moz-animation: 1s .2s ease both;
} @-webkit-keyframes shake {
%,% {
-webkit-transform: translateX();
} %,% {
-webkit-transform: translateX(-10px);
} %,% {
-webkit-transform: translateX(10px);
}
} @-moz-keyframes shake {
%,% {
-moz-transform: translateX();
} %,% {
-moz-transform: translateX(-10px);
} %,% {
-moz-transform: translateX(10px);
}
} #navList a {
text-decoration: none;
display: block;
width: 5em;
height: 20px;
float: left;
text-align: center;
font-weight: bold;
padding-top: 8px;
color: #;
} .blogStats {
float: right;
font-style: italic;
font-family: Georgia,'FZYaoTi',Microsoft YaHei;
\5B8B\4F53, sans-serif;
color: #;
margin-right: 1px;
text-align: right;
} /*主页文章列表*/
#main {
width: %;
text-align: left;
margin-top: 10px;
} #mainContent .forFlow {
margin-left: 22em;
float: none;
width: auto;
} #mainContent {
min-height: 200px;
padding: 0px 0px 10px ;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
float: left;
margin-left: -22em;
margin-top: ;
width: %;
} /*日期*/
.day {
text-decoration: none;
background: #FFF;
padding: 20px;
margin-bottom: -1px;
color: #;
font-size: 21px;
line-height: .5em;
float: left;
clear: right;
} .day:hover {
border: 1px solid #21759B;
position: relative;
z-index: ;
} .day:hover .postSeparator {
border-top: 1px dashed #;
} .dayTitle {
text-decoration: none;
} .dayTitle a {
text-decoration: none;
color: #;
font-size: 13px;
font-weight: bold;
font-family: Georgia,Consolas,Microsoft YaHei, monospace;
} /*文章标题*/
.postTitle {
font-family: Georgia,'Consolas','FZYaoTi','STHeiti',Microsoft YaHei;
\5B8B\4F53, sans-serif;
font: 'Lucida Console',Georgia,'Microsoft YaHei',Microsoft YaHei;
margin-bottom: 10px;
font-size: 20px;
font-weight: bold;
float: right;
width: %;
clear: both;
} .postTitle a:link, .postTitle a:visited, .postTitle a:active {
color: #21759b;
font-weight: bold;
transition: all .4s linear 0s;
} .postTitle a:hover {
text-decoration: none;
margin-left: 30px;
font-weight: bold;
color: #45bcf9;
} .postTitle2 {
text-decoration: none;
font-size: 20px;
font-weight: bold;
font-family: Georgia,'Consolas','FZYaoTi','STHeiti',Microsoft YaHei;
\5B8B\4F53, sans-serif;
font: 'Lucida Console',Georgia,'Microsoft YaHei',Microsoft YaHei;
padding-right: 64px;
padding-left: 10px;
border-left-style: solid;
border-left-width: 3px;
border-left-color: #;
} .postCon {
float: right;
line-height: .5em;
width: %;
clear: both;
padding: 10px ;
} .day .postTitle a {
padding-left: 10px;
} .postDesc {
border-right: 3px solid #21759b;
font-size: 12px;
color: #21759b;
float: right;
width: %;
clear: both;
text-align: right;
padding-left: 20px;
padding-right: 5px;
margin-top: 20px;
line-height: 1.5;
} .postDesc a:link, .postDesc a:visited, .postDesc a:active {
color: #;
} .postDesc a:hover {
color: #21759b;
text-decoration: none;
} .postSeparator {
clear: both;
height: 1px;
width: %;
clear: both;
float: right;
margin: auto 15px auto;
} /*侧边栏*/
#sideBar {
margin-top: -15px;
width: 240px;
min-height: 200px;
padding: 0px 0px 5px;
float: right;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
} #sideBar a {
color: #;
} #sideBar a:hover {
color: #21759b;
} .mySearch {
background: #FFF;
} .catListTitle {
font-size: 16px;
background-color: #169FE6;
color: white;
font-weight: normal;
margin-bottom: 5px;
} .catListEssay ul li {
font-size: 12px;
font-weight: normal;
margin-left: -.3em;
} .liScore {
font-family: Georgia,'Consolas','FZYaoTi','STHeiti',Microsoft YaHei;
font-size: 12px;
font-weight: normal;
margin-left: -.3em;
} .liRank {
font-family: Georgia,'Consolas','FZYaoTi','STHeiti',Microsoft YaHei;
font-size: 12px;
font-weight: normal;
margin-left: -.3em;
} .catListTag {
text-decoration: none;
background: #FFF;
margin-top: 10px;
margin-bottom: 20px;
} .catListTag ul {
border-top: none;
} .catListTag ul li {
line-height: 44px;
margin-left: -30px;
color: #7e8c8d;
} .catListPostArchive {
background: #FFF;
} .catListPostArchive ul {
border-top: none;
} .catListPostArchive ul li {
line-height: 44px;
color: #7e8c8d;
margin-left: -30px;
} .catListArticleCategory {
width: 290px;
padding-top: 20px;
background: #FFF;
margin-top: 20px;
} .catListImageCategory {
width: 290px;
padding-top: 20px;
background: #FFF;
margin-top: 20px;
} .catListComment {
background: #FFF;
margin-top: 20px;
} #RecentCommentsBlock {
padding: 10px;
border: 1px solid #dedede;
border-top: none;
} .recent_comment_title {
font-size: 15px;
color: #7e8c8d;
} .recent_comment_body, .recent_comment_author {
border-bottom: 1px solid #E9E9E9;
color: #9fa4a4;
font-size: 13px;
} .recent_comment_body {
border-bottom: none;
} .catListView {
background: #FFF;
margin-top: 20px;
} #TopViewPostsBlock {
padding: 10px;
border: 1px solid #dedede;
border-top: none;
} .catListView ul li {
border-bottom: 1px solid #E9E9E9;
margin-left: -30px;
margin-bottom: 5px;
} .catListFeedback {
background: #FFF;
margin-top: 20px;
} #TopFeedbackPostsBlock {
padding: 10px;
border-top: none;
} .catListFeedback ul li {
margin-left: -30px;
} .catListLink {
display: none;
} .clearFix:after {
clear: both;
display: block;
height: ;
line-height: ;
content: "";
visibility: hidden;
} #myding {
background: #99B16B;
display: none;
} #myadd:hover {
opacity: ;
} #goto-top:hover {
background: url(http://images.cnblogs.com/cnblogs_com/Li-Cheng/554829/o_goto-top.png) no-repeat 0 -36px;
} /*日历控件样式*/
#blog-calendar {
float: center;
width: 238px;
margin-top: 20px;
padding-bottom: 5px;
margin-bottom: 20px;
box-shadow: 1px 1px #ccc;
} #blog-calendar td {
font-size: 12px;
font-family: "Comic Sans MS";
} #blog-calendar th {
font-size: 12px;
} #calendar {
width: 238px;
padding-bottom: 5px;
margin-bottom: 35px;
box-shadow: 1px 1px #ccc;
} #calendar .Cal {
width: %;
line-height: .5em;
} #calendar td {
font-family: "Comic Sans MS";
background: #FFFFFF;
padding-top: 2px;
} .Cal {
border: none;
color: #;
text-decoration: none;
} #calendar table a:hover {
color: white;
text-decoration: none;
} .CalTodayDay {
background: #FFF !important;
text-decoration: none;
} .CalWeekendDay {
padding-top: 4px;
padding-bottom: 4px;
text-decoration: none;
} .CalOtherMonthDay {
color: #ccc;
padding-top: 4px;
padding-bottom: 4px;
text-decoration: none;
} #calendar .CalNextPrev a:link, #calendar .CalNextPrev a:visited, #calendar .CalNextPrev a:active {
font-weight: bold;
padding-left: 10px;
padding-right: 15px;
text-decoration: none;
} .CalDayHeader {
background: #F8F8F8;
font-weight: ;
color: #5E5F63;
text-decoration: none;
} .CalTitle { /**日历年月头部样式**/
background: #6293bb;
width: %;
height: 25px;
text-align: center;
font-size: 14px;
font-weight: bold;
padding: 5px ;
color: #FFF;
text-decoration: none;
} .CalTitle td {
background: #F8F8F8 !important;
border: 0px !important;
color: #5E5F63;
font-family: "Comic Sans MS";
text-decoration: none;
} .catListTitle {
font-size: 13px;
padding: 10px 20px;
background-color: #;
color: white;
font-weight: normal;
} .catListComment {
line-height: .5em;
} .divRecentComment {
text-indent: 2em;
color: #;
margin-bottom: 20px;
} #sideBarMain ul {
line-height: .5em;
} #sideBarMain li {
line-height: 1.8;
} #widget_my_zzk {
padding: 10px 15px;
margin-bottom: 3px;
} #widget_my_google {
padding: 10px 15px 15px;
margin: !important;
} .input_my_zzk {
width: 122px;
height: 35px;
outline: none;
line-height: 35px;
font-size: 13px;
padding: 5px;
} input.btn_my_zzk {
font-size: 13px;
height: 37px;
width: 70px;
background: #;
text-align: center;
line-height: 37px;
border: none;
color: #FFF;
font-family: "Microsoft Yahei", "Microsoft YaHei", Arial;
} input.btn_my_zzk:hover {
cursor: pointer;
cursor: hand;
} /*查看文章页面*/
#topics {
width: %;
min-height: 200px;
padding: 0px 0px 10px ;
float: left;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
word-break: break-all;
} #topics .postTitle {
border: 0px;
font-size: %;
font-weight: bold;
float: left;
line-height: .5em;
width: %;
padding-left: 5px;
} #EntryTag {
color: #;
} #EntryTag a {
margin-left: 5px;
height: 20px;
line-height: 20px;
color: #;
padding: 3px 14px;
border-radius: 10px;
margin: 2px 5px ;
background: #e7e7e7;
text-decoration: none;
} #EntryTag a:link, #EntryTag a:visited, #EntryTag a:active {
color: #;
} #EntryTag a:hover {
color: #f5f5f5;
background: #21759b;
transition: all .4s linear 0s;
} #BlogPostCategory {
color: #;
} #BlogPostCategory a {
margin-left: 5px;
height: 20px;
line-height: 20px;
color: #;
padding: 3px 14px;
border-radius: 10px;
margin: 2px 5px ;
background: #e7e7e7;
text-decoration: none;
} #BlogPostCategory a:link, #BlogPostCategory a:visited, #BlogPostCategory a:active {
color: #;
} #BlogPostCategory a:hover {
color: #f5f5f5;
background: #21759b;
} #topics .postDesc {
padding-left: 0px;
width: %;
text-align: right;
color: #;
margin-top: 5px;
background: none;
} .feedback_area_title {
font: normal normal 16px/35px "Microsoft YaHei";
margin: 10px 30px;
border-bottom: 2px solid #cccccc;
} .louzhu {
background: transparent url(http://images0.cnblogs.com/blog2015/618672/201508/201646262696155.png) no-repeat scroll right top;
padding-right: 16px;
} .feedbackListSubtitle {
color: #A8A8A8;
} .feedbackListSubtitle a:link, .feedbackListSubtitle a:visited, .feedbackListSubtitle a:active {
color: #21759b;
font-weight: bold;
} .feedbackListSubtitle a:hover {
color: #21759b;
text-decoration: underline;
} .feedbackListSubtitle b {
color: #21759b;
} .feedbackManage {
width: 200px;
text-align: right;
float: right;
} .feedbackCon {
border-bottom: 1px solid #EEE;
padding: 10px 20px 10px 5px;
min-height: 35px;
_height: 35px;
margin-bottom: 1em;
line-height: 1.5;
} #divRefreshComments {
text-align: right;
margin-bottom: 10px;
} .commenttb {
padding: 8px;
margin-bottom: 10px;
width: %;
color: #;
border: 1px solid #ddd;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
width: 320px;
} .commenttb:hover {
color: #;
border-color: rgba(, , , 0.8);
outline: ;
-webkit-box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
-moz-box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
transition: all .4s linear 0s;
} .commentTextBox {
width: 410px !important;
margin-top: 10px;
margin-bottom: 10px;
} .commentTextBox:hover {
color: #;
border-color: rgba(, , , 0.8);
outline: ;
-webkit-box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
-moz-box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
transition: all .4s linear 0s;
} #AjaxHolder_PostComment_btnSubmit {
padding: 8px 20px;
text-align: center;
font-size: 14px;
color: #fff;
border: none;
background: #21759b;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-o-transition: all .4s ease;
-ms-transition: all .4s ease;
transition: all .4s ease;
cursor: pointer;
display: inline-block;
vertical-align: middle;
outline: none;
text-decoration: none;
} #AjaxHolder_PostComment_btnSubmit:hover {
background: #;
} #AjaxHolder_PostComment_divCommnentArea tr {
margin-top: 10px;
margin-bottom: 10px;
} /*评论框*/
.comment_vote {
padding-right: 10px;
} .comment_vote a {
color: #;
} .comment_vote a:hover {
color: #21759b;
} #commentform_title {
font: normal normal 16px/35px "Microsoft YaHei";
margin: 10px 30px;
border-bottom: 2px solid #cccccc;
background-image: none;
padding: ;
} #comment_form_container .author {
padding-left: 10px;
color: #;
border: 1px solid #ddd;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
width: 320px;
height: 20px;
background-image: none;
} #comment_form_container p {
font-size: 14px;
margin-bottom: 20px;
} .commentbox_title_left {
font-size: 14px;
} .commentbox_title_right {
float: left;
} #comment_form_container .comment_textarea {
width: %;
height: 200px;
font-size: 13px;
padding: 8px;
margin-bottom: 10px;
color: #;
border: 1px solid #ddd;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
} #comment_form_container .comment_textarea:hover {
border-color: rgba(, , , 0.8);
outline: ;
transition: all .4s linear 0s;
} #comment_form_container .comment_textarea:focus {
outline: ;
} .comment_btn {
width: 100px;
height: 38px;
padding: 8px 20px;
text-align: center;
font-size: 14px;
color: #fff;
border: none;
background: #21759b;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-o-transition: all .4s ease;
-ms-transition: all .4s ease;
transition: all .4s ease;
cursor: pointer;
display: inline-block;
vertical-align: middle;
outline: none;
text-decoration: none;
} .comment_btn:hover {
background: #;
} #comment_form_container {
} /*列表页面*/
.entrylistTitle, .PostListTitle, .thumbTitle {
margin-bottom: 25px;
height: 38px;
line-height: 38px;
font-size: 16px;
border-bottom: 2px solid #e6e6e6;
} color: #21759b; .entrylistDescription {
color: #;
text-align: right;
padding-top: 5px;
padding-bottom: 5px;
padding-right: 10px;
margin-bottom: 10px;
} .entrylistItem {
min-height: 20px;
_height: 20px;
margin-bottom: 30px;
padding-bottom: 50px;
padding-top: 10px;
width: %;
} .entrylistPosttitle {
padding-left: 15px;
margin-bottom: 10px;
border-left: 3px solid #21759b;
font-size: 20px;
width: %;
} .entrylistPosttitle a:link, .entrylistPosttitle a:visited, .entrylistPosttitle a:active {
color: #21759b;
transition: all .4s linear 0s;
} .entrylistPosttitle a:hover {
margin-left: 30px;
color: #0f3647;
text-decoration: none;
} .entrylistPostSummary {
margin-top: 5px;
margin-bottom: 5px;
} .entrylistItemPostDesc {
margin-top: 12px;
text-align: right;
color: #;
padding-left: 5px;
} .entrylistItemPostDesc a:link, .entrylistItemPostDesc a:visited, .entrylistItemPostDesc a:active {
color: #;
} .entrylistItemPostDesc a:hover {
color: #21759b;
} .entrylist .postSeparator {
clear: both;
width: %;
font-size: ;
line-height: ;
margin: ;
padding: ;
height: ;
border: none;
} .divRecentCommentAticle a {
color: #;
} .pager {
text-align: right;
margin-right: 10px;
} .pager a {
box-shadow: 1px 3px #3671a5;
border: 1px solid #3671a5;
background: #3671a5;
color: white;
transition: all .4s linear 0s;
} .pager a:hover {
background: #;
} .PostList {
border-bottom: 1px solid #ccc;
clear: both;
min-height: .5em;
_height: .5em;
padding-top: 10px;
margin-bottom: 20px;
padding-bottom: 20px;
} .postTitl2 {
float: left;
padding-top: 10px;
padding-bottom: 10px;
font-size: 14px;
} .postDesc2 {
color: #;
float: right;
} .postText2 {
clear: both;
color: #;
} /*留言*/
.pfl_feedback_area_title {
text-align: right;
line-height: .5em;
font-weight: bold;
margin-bottom: 10px;
} .pfl_feedbackItem {
border: 1px dashed #ccc;
padding: 10px;
border-radius: 3px;
margin-bottom: 20px;
} .pfl_feedbacksubtitle {
width: %;
height: .5em;
} .pfl_feedbackname {
float: left;
} .pfl_feedbackname a {
color: #21759b;
font-weight: bold;
} .pfl_feedbackManage {
float: right;
} .pfl_feedbackCon {
color: black;
padding-top: 5px;
padding-bottom: 5px;
} .pfl_feedbackAnswer {
color: #F40;
text-indent: 2em;
} .tdSentMessage {
text-align: right;
} .errorMessage {
width: 300px;
float: left;
} #Profile1_panelAdd input[type=text], #Profile1_txtContent {
padding: 8px;
margin-bottom: 10px;
color: #;
border: 1px solid #ddd;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
} #Profile1_panelAdd input[type=text]:hover, #Profile1_txtContent:hover {
color: #;
border-color: rgba(, , , 0.8);
outline: ;
-webkit-box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
-moz-box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
box-shadow: inset 1px 1px 1px rgba(, , , 0.075), 4px rgba(, , , 0.6);
transition: all .4s linear 0s;
} #Profile1_panelAdd input[type=text]:focus, #Profile1_txtContent:focus {
outline: ;
border-color: rgba(, , , 0.8);
} #Profile1_panelAdd input[type=submit] {
padding: 8px 20px;
text-align: center;
font-size: 14px;
color: #fff;
border: none;
background: #21759b;
border-radius: 3px;
-moz-border-radius: 3px;
-webkit-border-radius: 3px;
-webkit-transition: all .4s ease;
-moz-transition: all .4s ease;
-o-transition: all .4s ease;
-ms-transition: all .4s ease;
transition: all .4s ease;
cursor: pointer;
display: inline-block;
vertical-align: middle;
outline: none;
text-decoration: none;
} #Profile1_panelAdd input[type=submit]:hover {
background: #;
} .feedbackListSubtitle {
clear: both;
color: #A8A8A8;
padding: 8px 5px;
} .feedbackItem {
margin-top: 30px;
} .divPhoto {
border: 1px solid #ccc;
padding: 2px;
margin-right: 10px;
} .thumbDescription {
color: #;
text-align: right;
padding-top: 5px;
padding-bottom: 5px;
padding-right: 10px;
margin-bottom: 30px;
} #footer {
color: #;
text-align: center;
min-height: 15px;
_height: 15px;
border-top: 1px solid #ededed;
margin-top: 50px;
padding-top: 10px;
margin-bottom: 10px;
} /*留言查看页面的个人信息*/
.personInfo {
margin-bottom: 20px;
} /*留言分页区域*/
.pages {
text-align: right;
} #RSignature {
border-top: #45bcf9 1px dashed;
border-right: #45bcf9 1px dashed;
border-bottom: #45bcf9 1px dashed;
border-left: #45bcf9 1px dashed;
padding-top: 12px;
padding-right: 12px;
padding-bottom: 12px;
padding-left: 140px;
color: #FFFFFF;
font-family: 微软雅黑;
font-size: 14px;
background: url(http://images0.cnblogs.com/blog2015/618672/201508/201508126601957.png) #45bcf9 no-repeat 1% 30%;
} #RSignature a {
color: white;
} #RSignature div {
line-height: 25px;
} /*第四部分:文章内容常用标签格式*/
/*文章内部常用标签格式*/
.postBody {
color: #;
line-height: 1.7;
font-size: 14px;
} .postBody p, .postCon p {
text-indent: 2em;
margin: auto 1em auto;
} .postBody h2 {
font-size: %;
margin: 15px auto 2px auto;
font-weight: bold;
} .postBody h3 {
font-size: %;
margin: 15px auto 2px auto;
font-weight: bold;
} .postBody h4 {
background-color: #;
color: white;
text-shadow: 1px rgba(, , , 0.5);
font-family: Consolas, Microsoft YaHei, 'Andale Mono', monospace;
direction: ltr;
text-align: center;
white-space: pre;
word-spacing: normal;
word-break: normal;
line-height: 1.5;
padding: 1em;
margin: .5em ;
overflow: auto;
border-radius: .5em;
-moz-tab-size: ;
-o-tab-size: ;
tab-size: ;
-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
font-size: .5px;
margin-top: 3em;
} .postBody h5 {
font-size: %;
margin: 15px auto 2px auto;
font-weight: bold;
color: #;
} .postBody a:link, .postBody a:visited, .postBody a:active {
text-decoration: underline;
} .postCon a:link, .postCon a:visited, .postCon a:active {
text-decoration: underline;
} .postBody ul, .postCon ul {
margin-left: 2em;
} .postBody li, .postCon li {
list-style-type: disc;
} .postBody blockquote {
background-repeat: no-repeat;
quotes: "\201C""\201D""\2018""\2019";
} blockquote:before {
color: #ccc;
content: open-quote;
font-size: 4em;
line-height: .1em;
vertical-align: -.4em;
} blockquote p {
display: inline;
} .buryit {
background: url(http://i1.tietuku.com/c1d363061fa080f2.png) no-repeat;
} .burynum {
display: none;
} #author_profile {
display: none;
} #green_channel {
float: left;
} #div_digg {
float: right;
} .myposts_title {
font-weight: bold;
text-align: center;
} #sideBar {
font-size: 12px;
} #sideBar h3 {
font-size: 14px;
} .c_b_p_desc {
font-size: 14px;
line-height: 1.7;
} /*页脚下一页*/
#nav_next_page {
line-height: 50px;
} #nav_next_page a {
background-color: #;
height: 40px;
line-height: 40px;
color: #fff;
display: inline-block;
padding: 25px;
text-decoration: none;
} /*隐藏多余信息*/
#ad_text_under_commentbox, #ad_under_post_holder {
display: none;
} /*顶一下*/
.diggnum {
font-size: 28px;
color: #6DA47D;
font-family: 'Microsoft Yahei';
} #div_digg {
position: fixed;
right: 180px;
bottom: 20px;
z-index: ;
background-color: #fff;
font-size: 12px;
width: 125px;
margin: 10px ;
padding: 5px;
text-align: center;
border: 3px solid #55895b;
border-radius: 5px;
} .diggit {
float: left;
width: 128px;
height: 128px;
background: url('http://images.cnblogs.com/cnblogs_com/libaoheng/305804/o_dig.gif') no-repeat;
background-position: ;
text-align: center;
cursor: pointer;
} .diggit:hover {
background-position: -128px ;
} .postBody h1 {
border-left: 5px solid #e84c3d;
padding-left: 10px;
background-color: #ECECEC;
} .postBody h2 {
padding-left: 20px;
border-bottom: 1px dashed #f00;
color: transparent;
background-color: black;
text-shadow: rgba(,,,0.5) 5px 6px, rgba(,,,0.2) 1px 3px 3px;
-webkit-background-clip: text;
} .blog_catalog {
display: none;
width: auto;
height: auto;
float: right;
position: fixed;
right: 180px;
bottom: 200px;
z-index: ;
background-color: #fff;
font-size: 12px;
margin: 10px ;
padding: 5px;
text-align: center;
border: 3px solid #55895b;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
-moz-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
} .blog_catalog > li > a {
background-color: #;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(, , )),to(rgb(, , )));
background-image: -webkit-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -moz-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -o-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -ms-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: linear-gradient(top, rgb(, , ), rgb(, , ));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=,StartColorStr='#727a86', EndColorStr='#505864');
-webkit-box-shadow: inset 0px 1px 0px 0px #878e98;
-moz-box-shadow: inset 0px 1px 0px 0px #878e98;
box-shadow: inset 0px 1px 0px 0px #878e98;
width: %;
height: .75em;
line-height: .75em;
text-indent: .75em;
display: block;
position: relative;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: ;
color: #fff;
text-shadow: 0px 1px 0px rgba(,,,.);
} .blog_catalog ul li a {
background: #fff;
border-bottom: 1px solid #efeff0;
width: %;
height: .75em;
line-height: .75em;
display: block;
position: relative;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: .923em;
font-weight: ;
color: #878d95;
} .blog_catalog ul li a:hover {
cursor: pointer;
} .blog_catalog > li > a:hover, .blog_catalog > li > a.active, .blog_catalog > li:target > a; /*add this*/ {
background-color: #35afe3;
background-image: -webkit-gradient(linear, left top, left bottom, from(rgb(, , )),to(rgb(, , )));
background-image: -webkit-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -moz-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -o-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: -ms-linear-gradient(top, rgb(, , ), rgb(, , ));
background-image: linear-gradient(top, rgb(, , ), rgb(, , ));
filter: progid:DXImageTransform.Microsoft.gradient(GradientType=,StartColorStr='#45c7eb', EndColorStr='#2698db');
border-bottom: 1px solid #103c56;
-webkit-box-shadow: inset 0px 1px 0px 0px #6ad2ef;
-moz-box-shadow: inset 0px 1px 0px 0px #6ad2ef;
box-shadow: inset 0px 1px 0px 0px #6ad2ef;
} .blog_catalog > li > a.active {
border-bottom: 1px solid #1a638f;
} .blog_catalog > li > a:before {
content: '';
background-image: url(../images/sprite.png);
background-repeat: no-repeat;
font-size: 36px;
height: 1em;
width: 1em;
position: absolute;
left: ;
top: %;
margin: -.5em ;
} .item1 > a:before {
background-position: ;
} .item2 > a:before {
background-position: -38px ;
} .item3 > a:before {
background-position: -38px;
} .item4 > a:before {
background-position: -38px -38px;
} .item5 > a:before {
background-position: -76px ;
} .blog_catalog > li > a span {
font-size: .857em;
display: inline-block;
position: absolute;
right: 1em;
top: %;
background: #48515c;
line-height: 1em;
height: 1em;
padding: .4em .6em;
margin: -.8em ;
color: #fff;
text-indent: ;
text-align: center;
-webkit-border-radius: .769em;
-moz-border-radius: .769em;
border-radius: .769em;
-webkit-box-shadow: inset 0px 1px 3px 0px rgba(, , , .), 0px 1px 0px 0px rgba(, , , .);
-moz-box-shadow: inset 0px 1px 3px 0px rgba(, , , .), 0px 1px 0px 0px rgba(, , , .);
box-shadow: inset 0px 1px 3px 0px rgba(, , , .), 0px 1px 0px 0px rgba(, , , .);
text-shadow: 0px 1px 0px rgba(,,,.);
font-weight: ;
} .blog_catalog > li > a:hover span,
.blog_catalog > li a.active span,
.blog_catalog > li:target > a span /*add this*/ {
background: #2173a1;
} .blog_catalog > li > ul li a:before {
font-size: 8px;
color: #bcbcbf;
position: absolute;
width: 1em;
height: 1em;
top: ;
left: -.7em;
} .blog_catalog > li > ul li:hover a,
.blog_catalog > li > ul li:hover a span,
.blog_catalog > li > ul li:hover a:before {
color: #32373D;
} .blog_catalog ul > li > a span {
font-size: .857em;
display: inline-block;
position: absolute;
right: 1em;
top: %;
/ background: #fff;
border: 1px solid #d0d0d3;
line-height: 1em;
height: 1em;
padding: .4em .7em;
margin: -.9em ;
color: #878d95;
text-indent: ;
text-align: center;
-webkit-border-radius: .769em;
-moz-border-radius: 769em;
border-radius: 769em;
text-shadow: 0px 0px 0px rgba(,,,.));
} /*additional*/ .blog_catalog > li > ul {
height: ;
overflow: hidden;
opacity: ;
filter: alpha(opacity=); /* IE6-IE8 */
-webkit-transition: opacity .9s ease-in-out;
-moz-transition: opacity .9s ease-in-out;
-o-transition: opacity .9s ease-in-out;
-ms-transition: opacity .9s ease-in-out;
transition: opacity .9s ease-in-out;
} .blog_catalog > li:target > ul {
height: auto; /*using auto nullifies the height transitions, but it makes things flexible which is more important*/
border-bottom: 1px solid #51555a;
opacity: ;
filter: alpha(opacity=); /* IE6-IE8 */
} #cnblogs_post_body ul li {
list-style-type: none;
margin-left: -30px;
} .blog_catalog_open {
width: auto;
height: auto;
float: right;
position: fixed;
right: 180px;
bottom: 200px;
z-index: ;
background-color: #fff;
font-size: 12px;
width: 125px;
margin: 10px ;
padding: 5px;
text-align: center;
border: 3px solid #55895b;
border-radius: 5px;
-webkit-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
-moz-box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
box-shadow: 0px 1px 3px 0px rgba(,,,.), 0px 0px 18px 0px rgba(,,,.);
cursor: pointer;
}

3.页角html代码

<script>
var digg = $('#mainContent');//the element I want to monitor
digg.bind('DOMNodeInserted', function(e) {
$('.buryit').remove();
}); $('#navList').children().each(function(){
$(this).prepend('<div class="border"></div>');
}); $('#cnblogs_post_body').append('<div id="blog_catalog_open" class="blog_catalog_open">展开目录</div>');
$('#cnblogs_post_body').append('<div id="blog_catalog" class="blog_catalog"><ul><li><a id="blog_catalog_close" class="blog_catalog_close">>折叠目录</a></li></ul></div>'); var id = ;
$('#cnblogs_post_body h1').each(function(){
$(this).attr('id','blog_catalog_id_'+id);
$('#blog_catalog ul').append('<li><a href="#blog_catalog_id_'+id+'">'+$(this).text()+'</a></li>');
id++;
}); $('#blog_catalog_open').click(function(){
$('#blog_catalog').show();
$('#blog_catalog_open').hide();
}); $('#blog_catalog_close').click(function(){
$('#blog_catalog').hide();
$('#blog_catalog_open').show();
});
</script>