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

博客园美化阅读模式

程序员文章站 2022-06-01 10:37:34
`为了自己能更加好的查看自己的总结以及让关注我的小可爱们能更加好的学习我弄了阅读模式` 一.直接上代码 二.补充hover特效 三.效果展示 ......

为了自己能更加好的查看自己的总结以及让关注我的小可爱们能更加好的学习我弄了阅读模式

一.直接上代码

放在页脚即可

<style>
    .read_book {
        background: url(https://images.cnblogs.com/cnblogs_com/pythonywy/1516412/o_greedread.png)
    }

    .not_read_book {
        background: url(https://images.cnblogs.com/cnblogs_com/pythonywy/1516412/o_notread.png)
    }

    .read_book_button {
        height: 38px;
        width: 38px;
        border-radius: 50%;
        border: none;
        position: fixed;
        bottom: 22px;
        left: 20px;
        outline: none;
    }

    .read_goend_button {
        background: url(https://images.cnblogs.com/cnblogs_com/pythonywy/1516412/o_goend2.png);
        height: 38px;
        width: 38px;
        border-radius: 50%;
        border: none;
        position: fixed;
        bottom: 67px;
        left: 20px;
        outline: none;
    }

        .read_gotop_button {
        background: url(https://images.cnblogs.com/cnblogs_com/pythonywy/1516412/o_gotop.png);
        height: 38px;
        width: 38px;
        border-radius: 50%;
        border: none;
        position: fixed;
        bottom: 112px;
        left: 20px;
        outline: none;
    }
</style>


<button class="read_gotop_button" style="display: none"></button>
<button class="read_goend_button" style="display: none"></button>
<button class="read_book_button not_read_book" style="display: none"></button>


<script>
    //判断是否出现正文出现正文的时候出现read按钮
    var topics = document.queryselector('#topics');
    var read_book_button = document.queryselector('.read_book_button');
    if (topics) {
        read_book_button.style.display = 'block'

    }

    //向上按钮点击事件
    var read_gotop_button = document.queryselector('.read_gotop_button');
    read_gotop_button.onclick = function () {
        window.scrollto(0, 0);
    };

    //向下按钮点击事件
    var read_goend_button = document.queryselector('.read_goend_button');
    read_goend_button.onclick = function () {
        window.scrollto(0,9999);
    };

    read_book_button.onclick = function () {
        //点击事情跟换类名
        var class_name = this.classlist[1];
        class_name == 'read_book' ? this.classname = 'read_book_button not_read_book' : this.classname = 'read_book_button read_book'

        //更换样式
        //头
        var head = document.queryselector('#header');
        //右侧
        var sidebar = document.queryselector('#sidebar');
        //评价栏
        var comment_form = document.queryselector('#comment_form');

        //正文无关的内容
        var blog_post_info_block = document.queryselector('#blog_post_info_block');
        var postdesc = document.queryselector('.postdesc');
        var footer = document.queryselector('#footer');
        var blog_comments_placeholder = document.queryselector('#blog-comments-placeholder');

        //向上的按钮
        var read_gotop_button = document.queryselector('.read_gotop_button');
        //向下的按钮
        var read_goend_button = document.queryselector('.read_goend_button');
        //文章
        var maincontent = document.queryselector('#maincontent');

        if (class_name == 'read_book') {
            head.style.display = 'block';
            sidebar.style.display = 'block';
            comment_form.style.display = 'block';
            blog_post_info_block.style.display = 'block';
            postdesc.style.display = 'block';
            footer.style.display = 'block';
            blog_comments_placeholder.style.display = 'block';
            read_gotop_button.style.display = 'none';
            read_goend_button.style.display = 'none';
            maincontent.style.width = '94%'
        } else {
            head.style.display = 'none';
            sidebar.style.display = 'none';
            comment_form.style.display = 'none';
            blog_post_info_block.style.display = 'none';
            postdesc.style.display = 'none';
            footer.style.display = 'none';
            blog_comments_placeholder.style.display = 'none';
            read_gotop_button.style.display = 'block';
            read_goend_button.style.display = 'block';
            maincontent.style.width = '120%'
        }
    }
</script>

二.补充hover特效

写在全局css样式中

@keyframes pulse {
    25% {
        transform: scale(1.05);
    }

    75% {
        transform: scale(.99);
    }
}
.read_goend_button:hover,.read_gotop_button:hover,.read_book_button:hover {
    animation-name: pulse;
    animation-duration: 1s;
    animation-timing-function: linear;
    animation-iteration-count: infinite;
    box-shadow: none;
}

三.效果展示

博客园美化阅读模式

博客园美化阅读模式