博客个性化
页面定制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;
}
<!-- 添加博客顶部博主信息-->
<p style="text-align: center;font-size:35px;margin-bottom:5px;margin-top:20px;opacity: 0.5">欢迎来到大兵的博客</p>
/* 5. 为博客文章添加目录导航 */
/* 定制生成博客目录的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(0, 220, 0);
}
#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 {
cursor: pointer;
}
#sideBarContents dd:hover, dt:hover {
color:#A7995A;
}
#sideBarContents dd{
margin-left:20px;
}
/* 定制推荐和反对按键 */
#div_digg{
position:fixed;
bottom:-10px;
width:120px;
right:20px;
box-shadow: 0 0 6px #0000FF;
border:2px solid #FF0000;
padding:4px;
background-color:#fff;
border-radius:4px 4px 4px 4px !important;
}
.icon_favorite {
background: transparent url('http://images.cnblogs.com/cnblogs_com/shwee/1218109/o_kj.gif') no-repeat 0 0;
padding-left: 15px;
}
#blog_post_info_block a {
text-decoration: none;
color: #5B9DCA;
padding: 3px;
}
/* 定制返回顶部按键 */
#toTop {
background: url(//http://images.cnblogs.com/cnblogs_com/shwee/1218109/o_toTop.bmp) no-repeat 0px top;
width: 57px;
height: 57px;
overflow: hidden;
position: fixed;
right: 180px;
bottom: 20px;
cursor: pointer;
}
/* 定制页面扩大按键 */
#divExpandViewArea{
position: fixed;
color: white;
padding: 10px 10px;
left: 0px;
top: 400px;
cursor: pointer;
opacity: 0.9;
background-color: #68228B;
}
/* 定制页面缩小按键 */
#divCollapseViewArea{
position: fixed;
color: white;
padding: 10px 10px;
left: 0px;
top: 445px;
cursor: pointer;
opacity: 0.9;
background-color: #68228B;
}
/* 定制公告栏文字信息 */
.gonggao{
text-align: center;
font-size:17px;
color:blue;
}
.wenzi{
text-align: center;
font-size:15px;
}
/* 定制公告栏时钟位置 */
#clockdiv {
/* left, center, right */
text-align: center;
}
/* 定制左侧随笔分类上下项之间的间距,左侧随笔分类显示有多少项,你就在后面增加多少项 */
#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;
}
#CatList_LinkList_0_Link_9{
margin-top:10px;
}
#CatList_LinkList_0_Link_10{
margin-top:10px;
}
#CatList_LinkList_0_Link_11{
margin-top:10px;
}
#CatList_LinkList_0_Link_12{
margin-top:10px;
}
#CatList_LinkList_0_Link_13{
margin-top:10px;
}
#CatList_LinkList_0_Link_14{
margin-top:10px;
}
/* 定制博客背景图片,url里面是你的图片位置信息 */
body {
background-color: #efefef;
background-image:url(http://images.cnblogs.com/cnblogs_com/shwee/1218109/o_bg_shw.jpg);
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center 0;
background-size: cover;
padding-top:0px;
}
/* 设置签名格式 定制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';
}
页首Html代码:
<!-- 创建新的导航栏,内容可更改为你自己的-->
<div id="shwtop" >
<ul style="margin-left:0px;margin-right: 0px;" class="test11" >
<div class="dropdown">
<a href="https://www.cnblogs.com/" class="dropbtn">博客园首页</span></a>
<div class="dropdown-content">
</div>
</div>
<div class="dropdown">
<a href="http://www.cnblogs.com/shwee/" class="dropbtn">我的首页</span></a>
<div class="dropdown-content">
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">全部分类</a>
<div class="dropdown-content">
<!-- <a class="menu" href="这里是你文章或随笔分类的链接地址,自己修改下面同理"> 这里更改下拉具体内容 </a> -->
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217679.html" >1.Linux基础</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1211712.html" >2.Python基础</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217691.html" >3.Python进阶</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217693.html" >4.项目实战</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217695.html" >5.人工智能</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1212750.html" >6.阅读笔记</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">Linux基础</a>
<div class="dropdown-content">
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217679.html" >1.基础知识</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217679.html" >2.Linux发行版本</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217679.html" >3.Linux命令行操作</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">Python基础</a>
<div class="dropdown-content">
<a class="menu" href="http://www.cnblogs.com/shwee/category/1211712.html" target="_Blank">1.认识Python</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1211712.html" target="_Blank">更多...</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">Python进阶</a>
<div class="dropdown-content">
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217691.html" target="_Blank">1.面向对象</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217691.html" target="_Blank">2.网络编程</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217691.html" target="_Blank">更多...</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">项目实战</a>
<div class="dropdown-content">
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217693.html" target="_Blank">1.这部分后续更新</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217693.html" target="_Blank">更多...</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">人工智能</a>
<div class="dropdown-content">
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217695.html" target="_Blank">1.机器学习</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217695.html" target="_Blank">2.深度学习</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217695.html" target="_Blank">3.计算机视觉</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217695.html" target="_Blank">4.自然语言处理</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217695.html" target="_Blank">5.图像处理</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1217695.html" target="_Blank">更多...</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">阅读人生</a>
<div class="dropdown-content">
<a class="menu" href="http://www.cnblogs.com/shwee/category/1212750.html" target="_Blank">1.学术著作</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1212750.html" target="_Blank">2.诗词歌赋</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1212750.html" target="_Blank">3.闲书杂文</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1212750.html" target="_Blank">4.报刊新闻</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1212750.html" target="_Blank">5.电影小说</a>
<a class="menu" href="http://www.cnblogs.com/shwee/category/1212750.html" target="_Blank">更多...</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">学习资源</a>
<div class="dropdown-content">
<a class="menu" href="https://docs.djangoproject.com/en/2.0/" target="_Blank">1.Django2.0官网</a>
<a class="menu" href="http://docs.jinkan.org/docs/flask/" target="_Blank">2.Flask文档</a>
<a class="menu" href="http://www.runoob.com/bootstrap/bootstrap-tutorial.html" target="_Blank">3.Bootstrap教程</a>
<a class="menu" href="http://www.django-rest-framework.org/" target="_Blank">4.REST framework官网</a>
</div>
</div>
<div class="dropdown">
<a href="#" class="dropbtn">娱乐休闲</a>
<div class="dropdown-content">
<a class="menu" href="http://music.163.com/" target="_Blank">1.云音乐</a>
<a class="menu" href="http://music.163.com/" target="_Blank">2.QQ音乐</a>
<a class="menu" href="https://www.bilibili.com/" target="_Blank">3.bilibili</a>
<a class="menu" href="http://yingyu.xdf.cn/list_907_1.html" target="_Blank">4.双语阅读</a>
<a class="menu" href="http://720yun.com/" target="_Blank">5.全景图片欣赏</a>
<a class="menu" href="https://weibo.com/" target="_Blank">6.微博</a>
<a class="menu" href="http://china.nba.com/" target="_Blank">7.NBA</a>
<a class="menu" href="https://www.toutiao.com/" target="_Blank">8.今日头条</a>
<a class="menu" href="https://tieba.baidu.com/f?kw=%C4%DA%BA%AD%B6%CE%D7%D3&fr=ala0&tpl=5" target="_Blank">9.内涵段子</a>
</div>
</div>
</ul>
</div>
<!-- 添加顶部滚动信息(公告)例子:《沁园春.雪》-->
<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>
<!-- 为页面添加分享功能按键 -->
<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":"340"},"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>
<!-- 指定返回顶部位置#shwtop -->
<a href="#shwtop"><div id="toTop" style="zoom:0;"></div></a>
<!-- 添加打赏功能按键 -->
<script src="http://static.tctip.com/tctip-1.0.0.min.js"></script>
<script>
new tctip({
top: '60%',
button: {
id: 9,
type: 'dashang',
},
list: [
{
type: 'alipay',
qrImg: 'https://files.cnblogs.com/files/shwee/alipay.bmp'
},
{
type: 'wechat',
qrImg: 'https://files.cnblogs.com/files/shwee/wechat.bmp'
}
]
}).init()
</script>
<!-- 添加页面放大和缩小功能按键 -->
<div id="divExpandViewArea" onclick="$('#main_container').css({'margin-left':'-195px'});$('#leftmenu').css({'display':'none'});">扩大</div>
<div id="divCollapseViewArea" onclick="$('#main_container').css({'margin-left':'0px'});$('#leftmenu').css({'display':'block'});">缩小</div>
<!-- 博客页面脚添加Github链接或其他链接 -->
<!-- 页面左上角 -->
<a href="https://shw2018.github.io/" 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="https://github.com/shw2018" 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>
博客侧边栏公告代码:
<!-- 添加公告栏图片并指向首页链接 -->
<div align="center">
<a href="https://www.cnblogs.com/ybChen/">
<img src="https://www.cnblogs.com/ybChen/"></a>
</div>
<p class="gonggao"><a style="color: blue;font-weight: bold;" href="https://www.cnblogs.com/ybChen/">我的博客目录结构</a></p>
<p class="wenzi">大兵的博客</p>
<p>-------------------------------</p>
<!-- 添加公告栏时钟 -->
<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>
<!-- 为页面添加爱心特效 -->
<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>
页脚Html代码:
<!-- 生成博客目录的JS代码,两级目录 -->
<script type="text/javascript">
/*
这段代码按H2、H3格式生成两级菜单
写博客按H2、H3格式写,不然生成不了
Markdown写作按##、###两级目录写
当然你也可以改写代码成三级菜单
参考:孤傲苍狼 zhang_derek
大兵 2018-5-18
*/
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);
//为右下角推荐推荐区域添加关注按钮
$('#div_digg').prepend('<div style="padding-bottom: 5px"><span class="icon_favorite" style="padding-top: 2px"></span><a onclick="cnblogs.UserManager.FollowBlogger(\'9a35f2c7-18ab-e111-aa3f-842b2b196315\');" href="javascript:void(0);" style="font-weight: bold; padding-left:5px;">关注一下楼主吧</a> </div>');
}
</script>
<!-- 添加顶部滚动信息(公告)例子:《沁园春.雪》-->
<div id="Scroll_info" style="text-align: center;color:black;font-size:16px;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>
-------------------------------------------
个性签名:独学而无友,则孤陋而寡闻。做一个灵魂有趣的人!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!
万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!