zoukankan      html  css  js  c++  java
  • 博客园主题美化

    主题作者的博客:https://www.cnblogs.com/Dy1an/,感谢作者!

    本博客就是使用当前主题,具体效果如下:

    效果图

    使用方法是:禁用模板默认CSS,然后在管理界面填入自定义样式

    页面定制 CSS 代码

    * {
        margin: 0;
        padding: 0
    }
    
    
    
    a {
        text-decoration: none;
        color: #1c2b36
    }
    
    body {
        background-color: #fff;
        font-size: 13px;
        letter-spacing: 1px
    }
    
    #header {
        background-image: url(https://img2018.cnblogs.com/blog/979767/201911/979767-20191115092708101-1793403956.jpg);
        background-size: cover;
        min-height: 600px;
    }
    
    #header::after {
        content: "";
        position: absolute;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        opacity: .8;
        background: #1C1D21;
        height: 600px;
    }
    
    
    #header a,
    h1,
    img {
        z-index: 1;
        color: white;
        position: relative;
    }
    
    #header #blogTitle {
        height: 100px;
        line-height: 100px;
        vertical-align: middle;
        position: relative;
        left: 0;
        right: 0;
        margin: auto;
         1310px;
    }
    
    #blogTitle h1>a:after {
        content: "'s OPS BLOG"
    }
    
    #blog_nav_sitehome {
    	opacity: 0;
    }
    
    #header #navigator {
        height: 100px;
        line-height: 100px;
        vertical-align: middle;
        position: relative;
        top: -100px;
        left: 0;
        right: 0;
        margin: auto;
         1310px;
        text-align: right;
    }
    
    #header #navigator li>a:hover {
        color: #ea0000
    }
    
    #header a {
        letter-spacing: 1px;
    }
    
    #header h1 a {
        font-family: Impact;
        letter-spacing: 1px;
    }
    
    #header li {
        list-style: none;
        display: inline-block;
    }
    
    #header li a {
        font-size: 18px;
        letter-spacing: 2.5px;
        text-transform: uppercase;
        font-weight: 550;
    }
    
    #lnkBlogLogo {
        display: none;
    }
    
    .blogStats {
        display: none;
    }
    
    .my-hd-row {
        height: 400px;
        display: block;
        position: relative;
        top: -100px;
        left: 0;
        right: 0;
        margin: auto;
         1310px;
    }
    
    .my-hd-body {
        padding-top: 50px;
    }
    
    .my-hd-body-left {
        display: block;
        float: left;
         810px;
        padding: 80px 0;
        height: 340px;
    }
    
    .my-hd-body-left h1 {
        color: white;
        letter-spacing: 2px;
        font-size: 34px;
        line-height: 60px;
    }
    
    .my-hd-body-right {
        display: block;
        float: right;
         500px;
        height: 340px;
        padding: 80px 0;
        text-align: right;
    }
    
    .my-hd-btn {
        margin-top: 70px;
        display: block;
        box-sizing: border-box;
        border: 2px solid #fff;
        border-radius: 30px;
        font-size: 15px;
        font-weight: 600;
        padding: 5px 20px;
        cursor: pointer;
         240px;
    }
    
    .my-hd-btn:hover {
        border: 2px solid gold;
        background-color: gold;
        color: #003366 !important;
    }
    
    #main {
        position: relative;
         1310px;
        padding-right: 15px;
        padding-left: 15px;
        margin-right: auto;
        margin-left: auto
    }
    
    #main .entrylistTitle {
        color:#1c2b36;
    }
    
    #mainContent {
        margin-right: 10px;
         900px;
        float: left;
        background-color: white;
        padding: 15px;
        border-radius: 2px
    }
    
    #mainContent .forFlow {
        /* border: 1px dashed #ddd; */
        /* background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.04) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.04) 3%, rgba(0, 0, 0, 0) 3%); */
        background-size: 20px 20px;
        background-position: center center;
    }
    
    #mainContent .day {
        position: relative;
        margin: 0 0 10px 0;
        padding: 15px;
        display: block
    }
    
    #mainContent .dayTitle {
        display: none
    }
    
    #mainContent .day .postTitle {
        display: inline-block;
        height: 22px;
        line-height: 22px;
        font-size: 20px;
        font-weight: bolder;
        vertical-align: middle;
        border-left: 4px solid #c40000;
        position: relative;
        left: -17px;
        margin-bottom: 15px
    }
    
    #mainContent .postTitle>a {
        margin-left: 13px
    }
    
    #mainContent .postTitle>a:hover {
        color: #036
    }
    
    #mainContent .day .postCon .c_b_p_desc {
        line-height: 23px;
        font-size: 12px;
        opacity: .7;
        margin-bottom: 10px;
        height: 50px;
        overflow: hidden
    }
    
    #mainContent .day .postCon .c_b_p_desc:after {
        content: " . . ."
    }
    
    #mainContent .day .postCon .c_b_p_desc>a {
        display: none
    }
    
    #mainContent .day .postDesc {
        font-size: 12px;
        opacity: .7
    }
    
    #mainContent .day .postDesc a:hover {
        color: #ea0000
    }
    
    #sideBar {
         340px;
        float: left
    }
    
    #sideBar a:hover {
        color: #ea0000
    }
    
    #sideBar h3 {
        border-left: 3px solid #cf2730;
        padding-left: 10px;
        margin-bottom: 10px
    }
    
    #sideBar .newsItem {
        background-color: white;
        /* background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.04) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.04) 3%, rgba(0, 0, 0, 0) 3%); */
        background-size: 20px 20px;
        background-position: center center;
        padding: 15px;
        border-radius: 2px;
        margin-bottom: 10px
    }
    
    #profile_block {
        margin-top: 5px
    }
    
    #sideBar .newsItem #blog-news {
        line-height: 25px
    }
    
    #profile_block {
        padding-top: 10px;
        line-height: 25px
    }
    
    #leftcontentcontainer .sidebar-block {
        background-color: white;
        /* background-image: linear-gradient(90deg, rgba(50, 0, 0, 0.04) 3%, rgba(0, 0, 0, 0) 3%), linear-gradient(360deg, rgba(50, 0, 0, 0.04) 3%, rgba(0, 0, 0, 0) 3%); */
        background-size: 20px 20px;
        background-position: center center;
        margin-bottom: 10px;
        padding: 15px
    }
    
    #leftcontentcontainer #sidebar_search_box #widget_my_zzk {
        padding-top: 10px;
    }
    
    #leftcontentcontainer #sidebar_search_box #widget_my_zzk .input_my_zzk {
         205px;
        height: 28px;
        vertical-align: middle;
        padding: 0 12px;
        font-size: 13px;
        color: #555;
        background-color: #fff;
        background-image: none;
        border: 1px dashed #ccc
    }
    
    #leftcontentcontainer #sidebar_search_box #widget_my_zzk .btn_my_zzk {
        line-height: 30px;
        height: 30px;
        vertical-align: middle;
         70px;
        font-weight: 400;
        color: #555;
        text-align: center;
        background-color: white;
        border: 1px dashed #ccc;
        font-size: 13px;
        letter-spacing: 1px
    }
    
    #leftcontentcontainer #sidebar_search_box #widget_my_zzk .btn_my_zzk:hover {
        cursor: pointer
    }
    
    #leftcontentcontainer #sidebar_categories ul {
        padding-top: 5px;
        list-style: none
    }
    
    #leftcontentcontainer #sidebar_categories ul>li {
        line-height: 35px;
    }
    
    #leftcontentcontainer #sidebar_categories ul>li:before {
        content: " - "
    }
    
    #leftcontentcontainer #sidebar_topviewedposts #TopViewPostsBlock {
        padding-top: 10px;
    }
    
    #leftcontentcontainer #sidebar_topviewedposts #TopViewPostsBlock ul {
        list-style: none
    }
    
    #leftcontentcontainer #sidebar_topviewedposts #TopViewPostsBlock li {
        line-height: 35px;
         300px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden
    }
    
    #leftcontentcontainer #sidebar_topcommentedposts #TopFeedbackPostsBlock {
        padding-top: 10px;
    }
    
    #leftcontentcontainer #sidebar_topcommentedposts #TopFeedbackPostsBlock ul {
        list-style: none
    }
    
    #leftcontentcontainer #sidebar_topcommentedposts #TopFeedbackPostsBlock li {
        line-height: 35px;
         300px;
        text-overflow: ellipsis;
        white-space: nowrap;
        overflow: hidden
    }
    
    #leftcontentcontainer #call_me_box {
        padding-top: 10px;
        border-top: 1px;
        text-align: center
    }
    
    #footer {
        margin-top: 10px;
        height: 50px;
        line-height: 50px;
        vertical-align: center;
        text-align: center
    }
    
    #mainContent .postBody {
        margin-top: 50px !important
    }
    
    #mainContent a:hover {
        color: #ea0000
    }
    
    #mainContent .postBody pre {
        padding: 10px
    }
    
    #mainContent .postBody table {
        border-spacing: 0;
         100%;
        border-collapse: collapse
    }
    
    #mainContent .postBody table thead {
        background-color: #1c2b36
    }
    
    #mainContent .postBody table th {
        font-size: 14px;
        font-weight: normal;
        padding: 8px;
        color: white;
        text-align: left;
        border: 1px solid #1c2b36
    }
    
    #mainContent .postBody table td {
        font-size: 12px;
        padding: 8px;
        border: 1px solid #ccc
    }
    
    #cnblogs_post_body th,
    .cnblogs-post-body th {
        background-color: #1c2b36
    }
    
    #topics .post .postTitle {
        /* text-align: center; */
        /* padding: 30px 0; */
    }
    
    #mainContent .postTitle>a {
        margin-left: 13px;
        /* color: #cf2730; */
    }
    
    #topics .post .postBody #cnblogs_post_body {
        padding: 10px
    }
    
    #topics .post .postBody #cnblogs_post_body img {
        max- 880px;
        /* border: 1px dashed green; */
    }
    
    #mainContent .postBody p {
        font-size: 12px;
        letter-spacing: 2px;
        line-height: 30px
    }
    
    #cnblogs_post_body {
        margin-bottom: 10px
    }
    
    #blog_post_info_block {
        margin-top: 10px
    }
    
    #topics .post .postBody #blog_post_info_block {
        padding: 10px
    }
    
    #topics .post .postDesc {
        padding: 10px;
        margin-top: 10px
    }
    
    #blog-comments-placeholder {
        padding: 10px;
        margin-top: 10px
    }
    
    #blog-comments-placeholder br {
        display: none
    }
    
    #blog-comments-placeholder .feedback_area_title {
        font-size: 18px;
        font-weight: bold;
        padding-bottom: 10px;
        border-bottom: 1px dashed #ebebeb
    }
    
    #blog-comments-placeholder .feedbackItem {
        padding: 10px 0;
        border-bottom: 1px dashed #ebebeb
    }
    
    #blog-comments-placeholder .feedbackItem a:hover {
        color: #ea0000
    }
    
    #blog-comments-placeholder .feedbackListSubtitle {
        display: inline-block;
        padding: 10px 0
    }
    
    #blog-comments-placeholder .feedbackListSubtitle a {
        color: orangered;
        font-weight: bold
    }
    
    #blog-comments-placeholder .feedbackManage {
        float: right
    }
    
    #blog-comments-placeholder .feedbackManage .comment_actions a {
        padding-left: 5px;
        color: #146a80;
        font-weight: normal
    }
    
    #blog-comments-placeholder .feedbackListSubtitle .louzhu {
        color: gold;
        background-color: #1c2b36;
        padding: 1px 10px;
        border-radius: 2px;
        position: relative
    }
    
    #blog-comments-placeholder .feedbackManage .comment_actions a:hover {
        color: #ea0000
    }
    
    #blog-comments-placeholder .feedbackCon {
        line-height: 30px
    }
    
    #blog-comments-placeholder .feedbackCon .comment_vote a {
        padding-right: 5px;
        color: #146a80;
        font-weight: normal
    }
    
    #comment_nav {
        padding: 10px;
        margin-top: 10px;
        line-height: 30px
    }
    
    #blog-comments-placeholder .feedbackCon .comment_vote a:hover {
        color: #c40000
    }
    
    #comment_form #comment_nav a {
        padding-right: 10px;
        color: #146a80
    }
    
    #comment_form #comment_nav a:hover {
        color: #ea0000
    }
    
    #comment_form_container {
        padding: 10px;
        margin-top: 10px;
        line-height: 30px
    }
    
    #comment_form_container #commentform_title {
        font-size: 18px;
        font-weight: bold;
        padding-bottom: 10px;
        border-bottom: 1px dashed #ebebeb
    }
    
    #comment_form_container textarea {
         855px;
        height: 150px;
        border: 1px dashed #ebebeb;
        padding: 10px;
        letter-spacing: 1px
    }
    
    #comment_form_container #commentbox_opt {
        margin-top: 10px
    }
    
    #comment_form_container #commentbox_opt>input {
        margin-bottom: 10px;
        font-weight: 400;
        text-align: center;
        vertical-align: middle;
        cursor: pointer;
        border: 1px solid transparent;
        padding: 5px 10px;
        font-size: 12px;
        line-height: 1.5;
        border-radius: 3px;
        display: block;
         100%;
        background-color: #2f889a;
        color: white
    }
    
    #comment_form_container #commentbox_opt>a {
        color: #146a80
    }
    
    #ad_t2 {
        display: none
    }
    
    #cnblogs_c1 {
        display: none
    }
    
    #under_post_news {
        display: none
    }
    
    #cnblogs_c2 {
        display: none
    }
    
    #under_post_kb {
        display: none
    }
    
    .my-title {
        display: block;
        border-left: 5px solid #cf2730;
        padding-left: 10px;
        font-size: 20px !important;
        font-weight: bolder;
        line-height: 40px !important;
        background-color: #f8f8f8;
        color: #1c2b36;
        margin-top: 0px !important;
        margin-bottom: 0px !important;
    }
    
    #green_channel {
        padding: 0;
        margin-bottom: 10px;
        margin-top: 10px;
        border: 0;
        font-size: 12px;
         100%;
        text-align: left
    }
    
    #author_profile #author_profile_info img {
        border-radius: 50%;
        margin-right: 15px
    }
    
    #mainContent .c_b_p_desc {
        line-height: 23px;
        font-size: 12px;
        opacity: .7;
        margin-bottom: 10px;
        height: 50px;
        overflow: hidden
    }
    
    #mainContent .day .postSeparator {
        position: relative;
        height: 10px;
        line-height: 10px;
        margin: 15px 0;
        left: -16px;
         898px;
    }
    
    #mainContent .c_b_p_desc:after {
        content: " . . ."
    }
    
    #mainContent .c_b_p_desc>a {
        display: none
    }
    
    #mainContent .entrylistItem {
        position: relative;
        margin: 0 0 10px 0;
        padding: 15px;
        display: block
    }
    
    #mainContent .entrylistItem .entrylistPosttitle {
        display: inline-block;
        height: 22px;
        line-height: 22px;
        font-size: 20px;
        font-weight: bolder;
        vertical-align: middle;
        border-left: 4px solid #c40000;
        position: relative;
        left: -17px;
        margin-bottom: 15px
    }
    
    #mainContent .entrylistPosttitle>a {
        margin-left: 13px
    }
    
    #mainContent .entrylistItem .entrylistItemPostDesc {
        font-size: 12px;
        opacity: .7
    }
    
    #mainContent .entrylistItem .entrylistItemPostDesc a:hover {
        color: #ea0000
    }
    
    #mainContent .entrylistTitle {
        text-align: center;
        padding-bottom: 30px;
        margin-bottom: 10px
    }
    
    blockquote {
        border: 0;
        padding: 5px 20px;
        margin: 0;
        font-size: 14px;
        border-left: 5px solid #eee;
        background-color: #f8f8f8;
    }
    
    blockquote pre {
        padding: 5px !important;
        font-size: 14px
    }
    
    blockquote pre {
        padding: 5px !important;
        font-size: 14px
    }
    
    @media(max-970px) {
        #header {
            display: none;
        }
    
        #blogTitle h1 {
            display: none
        }
    
        .my-hd-body-right {
            display: none;
        }
    
        #main {
            top: 0;
            padding-right: 0px;
            padding-left: 0px;
            margin-top: 0px;
        }
    
        #header {
            min- 100% !important;
            padding-left: 0;
            padding-right: 0;
            min-height: 350px;
        }
    
        .blogStats {
            display: none;
        }
    
        #header #navigator {
            float: left;
            padding-left: 15px;
        }
    
        #header li a {
            font-size: 20px;
            font-weight: bolder;
        }
    
        .my-hd-body-left {
            display: block;
            float: left;
             auto;
            padding: 0 15px;
        }
        
        .my-hd-body-left h1 {
            color: white;
            letter-spacing: 2px;
            font-size: 18px;
            line-height: 50px;
        }
    
        .my-hd-btn {
            display: none;
        }
    
        #mainContent .day .postSeparator {
             100% !important
        }
    
        #mainContent {
            margin-right: 0 !important
        }
    
        #sideBar {
            margin-top: 10px !important;
            margin-left: 0 !important;
            margin-right: 0 !important
        }
    
        .commentform {
            margin-left: 0 !important;
            margin-right: 0 !important
        }
    
        #comment_form_container textarea {
             100% !important;
            padding: 0 !important
        }
    
        #cnblogs_post_body table {
            display: inline !important
        }
    
        #topics .postTitle a {
            font-size: 20px;
        }
    
        #topics .post .postBody #cnblogs_post_body img {
            max- 100%;
            border: 1px dashed green;
        }
    
        #mainContent .postBody table td {
            white-space: normal !important
        }
    
        .commentbox_title_right {
            display: none;
        }
    
        #mainContent .day .postTitle {
            display: inline-block;
            height: 22px;
            line-height: 22px;
            font-size: 18px;
            font-weight: bolder;
            vertical-align: middle;
            border-left: 4px solid #c40000;
            position: relative;
            left: -17px;
            margin-bottom: 15px;
             100%;
            white-space: nowrap;
            overflow: hidden;
        }
    
        #mainContent .entrylistItem .entrylistPosttitle {
            display: inline-block;
            height: 22px;
            line-height: 22px;
            font-size: 20px;
            font-weight: bolder;
            vertical-align: middle;
            border-left: 4px solid #c40000;
            position: relative;
            left: -17px;
            margin-bottom: 15px;
             100%;
            white-space: nowrap;
            overflow: hidden;
        }
    }
    
    #cnblogs_post_body p {
        margin: 0 !important;
        text-indent: 0;
    }
    
    .topicListFooter {
        margin-bottom: 10px;
    }
    
    #poweredby {
        display: none;
    }
    
    #mainContent {
        border-right: 1px dashed lightgray;
        padding-right: 10px;
    }
    
    /*生成博客目录的CSS*/
    #uprightsideBar{
        font-size:12px;
        font-family:Arial, Helvetica, sans-serif;
        text-align:left;
        position:fixed;/*将div的位置固定到距离top:50px,right:0px的位置,这样div就会处在最右边的位置,距离顶部50px*/
        top:50px;
        right:0px;
         auto;
        height: auto; 
    }
    #sideBarTab{
        float:left;
        30px; 
        border:1px solid #e5e5e5;
        border-right:none;
        text-align:center;
        background:#ffffff;
    }
    
    #sideBarContents{
        float:left;
        overflow:auto; 
        overflow-x:hidden;!important;
        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;
    }
    

    页首 HTML 代码

    <script>
        // 创建一个标签,将标签添加到指定标签里面
        var myEle = '<div class="my-hd-row"><div class="my-hd-body my-hd-body-left"><h1 class="">WELCOME! THIS IS A DOCUMENT WEBSITE RELATED TO OPERATION AND MAINTENANCE WORK.</h1><a class="my-hd-btn" href="https://github.com/senup" target="_blank">VISIT THE GITHUB NOW</a></div><div class="my-hd-body my-hd-body-right"><img class="img-fluid" src="https://img2018.cnblogs.com/blog/979767/201911/979767-20191118181141199-298692443.png" alt="Image" style="height: 300px;"></div></div>'
        document.getElementById('header').insertAdjacentHTML("beforeEnd", myEle);
    
        var githubEle = '<li><a target="_blank" class="menu" href="https://github.com/senup">GITHUB</a></li>';
        // 四个参数 beforeBegin、 afterBegin、beforeEnd、afterEnd
        document.getElementById('navList').insertAdjacentHTML("beforeEnd", githubEle);
    
    
        var callMeEle = '<div id="call_me" class="sidebar-block"><div><h3 class="catListTitle">联系我</h3><div id="call_me_box"><img src="https://images.cnblogs.com/cnblogs_com/senup/1605470/o_191203051539avatar.jpg" alt="" style="100px" ></div></div></div>'
        document.getElementById('blog-sidecolumn').insertAdjacentHTML("beforeEnd", callMeEle);
    </script>
    
    
    <script>
        // 点击页面小心心
        (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{ 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: ''; 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>
    
    
    
    <script type="text/javascript">
    /*
        功能:生成博客目录的JS工具
        测试:IE8,火狐,google测试通过
        孤傲苍狼
        2014-5-11
    */
    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>
    
    
    
    
    
    
    
    
    <script language="javascript" type="text/javascript">
    // 生成目录索引列表
    
    function GenerateContentList()
    {
        var mainContent = $('#cnblogs_post_body');
        var h2_list = $('#cnblogs_post_body h3');//如果你的章节标题不是h2,只需要将这里的h2换掉即可
    
        if(mainContent.length < 1)
            return;
     
        if(h2_list.length>0)
        {
            var content = '<a name="_labelTop"></a>';
            content += '<div id="navCategory" style="color:#152e97;">';
            content += '<p style="font-size:18px;"><b>目录</b></p>';
            content += '<ul>';
            for(var i=0; i<h2_list.length; i++)
            {
                var go_to_top = '<div style="text-align: right;"><a href="#_labelTop" style="color:#f68a33">回到顶部</a><a name="_label' + i + '"></a></div>';
                $(h2_list[i]).before(go_to_top);
                
                var h3_list = $(h2_list[i]).nextAll("h3");
                var li3_content = '';
                for(var j=0; j<h3_list.length; j++)
                {
                    var tmp = $(h3_list[j]).prevAll('h2').first();
                    if(!tmp.is(h2_list[i]))
                        break;
                    var li3_anchor = '<a name="_label' + i + '_' + j + '"></a>';
                    $(h3_list[j]).before(li3_anchor);
                    li3_content += '<li><a href="#_label' + i + '_' + j + '">' + $(h3_list[j]).text() + '</a></li>';
                }
                
                var li2_content = '';
                if(li3_content.length > 0)
                    li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a><ul>' + li3_content + '</ul></li>';
                else
                    li2_content = '<li><a href="#_label' + i + '">' + $(h2_list[i]).text() + '</a></li>';
                content += li2_content;
            }
            content += '</ul>';
            content += '</div><p>&nbsp;</p>';
            content += '<hr style="height:1px;border:none;border-top:1px dashed #0066CC;"/>';
            if($('#cnblogs_post_body').length != 0 )
            {
                $($('#cnblogs_post_body')[0]).prepend(content);
            }
        }   
    }
    
    GenerateContentList();
    </script>
    

    页脚 HTML 代码

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jQuery火箭图标返回顶部代码</title>
    <!--script src="js/jquery.js?v=1.83.min" type="text/javascript"></script-->
    <script src="https://common.cnblogs.com/script/jquery.js?v=1.7.min" type="text/javascript"></script>
    
    <style type="text/css">
    
    body{height:3000px;}
    
    /*回到顶部*/
    #rocket-to-top div {
        left: 0;
        margin: 0;
        overflow: hidden;
        padding: 0;
        position: absolute;
        top: 0;
         149px;
    }
    #rocket-to-top .level-2 {
        background: url("http://images.cnblogs.com/cnblogs_com/xujingyang/1227088/o_o_rocket_button_up.png") no-repeat scroll -149px 0 transparent;
        display: none;
        height: 250px;
        opacity: 0;
        z-index: 1;
    }
    #rocket-to-top .level-3 {
        background: none repeat scroll 0 0 transparent;
        cursor: pointer;
        display: block;
        height: 150px;
        z-index: 2;
    }
    #rocket-to-top {
        background: url("http://images.cnblogs.com/cnblogs_com/xujingyang/1227088/o_o_rocket_button_up.png") no-repeat scroll 0 0 transparent;
        cursor: default;
        display: block;
        height: 250px;
        margin: -125px 0 0;
        overflow: hidden;
        padding: 0;
        position: fixed;
        right: 0;
        top: 80%;
         149px;
        z-index: 11;
    }
    
    
        
    </style>
    
    
    <script type="text/javascript">
    
    // jQuery火箭图标返回顶部代码
    
    $(function() {
        var e = $("#rocket-to-top"),
        t = $(document).scrollTop(),
        n,
        r,
        i = !0;
        $(window).scroll(function() {
            var t = $(document).scrollTop();
            t == 0 ? e.css("background-position") == "0px 0px" ? e.fadeOut("slow") : i && (i = !1, $(".level-2").css("opacity", 1), e.delay(100).animate({
                marginTop: "-1000px"
            },
            "normal",
            function() {
                e.css({
                    "margin-top": "-125px",
                    display: "none"
                }),
                i = !0
            })) : e.fadeIn("slow")
        }),
        e.hover(function() {
            $(".level-2").stop(!0).animate({
                opacity: 1
            })
        },
        function() {
            $(".level-2").stop(!0).animate({
                opacity: 0
            })
        }),
        $(".level-3").click(function() {
            function t() {
                var t = e.css("background-position");
                if (e.css("display") == "none" || i == 0) {
                    clearInterval(n),
                    e.css("background-position", "0px 0px");
                    return
                }
                switch (t){
                case "0px 0px":
                    e.css("background-position", "-298px 0px");
                    break;
                case "-298px 0px":
                    e.css("background-position", "-447px 0px");
                    break;
                case "-447px 0px":
                    e.css("background-position", "-596px 0px");
                    break;
                case "-596px 0px":
                    e.css("background-position", "-745px 0px");
                    break;
                case "-745px 0px":
                    e.css("background-position", "-298px 0px");
                }
            }
            if (!i) return;
            n = setInterval(t, 50),
            $("html,body").animate({scrollTop: 0},"slow");
        });
    });
    
    </script>
    
    
    
    </head>
    <body>
    <center>
    <h2>jQuery火箭图标返回顶部代码</h2>
    <h3>滚动滑动条后,查看右下角查看效果。很炫哦!!</h3>
    </center>
    
    
    <!-- 火箭 -->
    <div style="display: none;" id="rocket-to-top">
        <div style="opacity:0;display: block;" class="level-2"></div>
        <div class="level-3"></div>
    </div>
    
    
    <div style="text-align:center;margin:50px 0; font:normal 14px/24px 'MicroSoft YaHei';">
    <p>适用浏览器:IE8、360、FireFox、Chrome、Safari、Opera、傲游、搜狗、世界之窗.</p>
    </div>
    </body>
    </html>
    
  • 相关阅读:
    UVA12096
    Phonegap
    苹果证书的申请、unityoc交互基础
    撸代码--linux进程通信(基于共享内存)
    在Mac上ppt导出pdf
    Tour UVA
    2144 砝码称重 2
    1553 互斥的数
    P1063 能量项链
    P1041 传染病控制
  • 原文地址:https://www.cnblogs.com/senup/p/11976610.html
Copyright © 2011-2022 走看看