window.onload = function(){
    // 刷新回到顶部
    setTimeout(() => window.scrollTo(0,0), 14)
   
    // 侧边二维码
    var qr_code = document.getElementsByClassName("qr_code")[0];
    var code_img = this.document.getElementsByClassName("code_img")[0];
    qr_code.onmouseover = function () {
        code_img.style.opacity = 1;
        code_img.style.animation = "rightLeft .8s  ease-in-out forwards"
    }
    qr_code.onmouseout = function () {
        code_img.style.opacity = 0;
        code_img.style.animation = ""
    }

    // 返回顶部
    var go_top = document.getElementsByClassName("go_top")[0];
    go_top.onclick = function backTop () {
        clearInterval(timer);  
        var timer = setInterval(function() {  
            let scrollHeight = document.documentElement.scrollTop || document.body.scrollTop;  
            let now = scrollHeight;  
            let speed = (2 - now) / 15;                               
            speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);  
            if (scrollHeight === 0) {                          
                clearInterval(timer);                             
            }  
            document.documentElement.scrollTop = scrollHeight + speed;    
            document.body.scrollTop = scrollHeight + speed;      
        }, 14); 
        window.onmousewheel = function(){
            clearInterval(timer);
        }
        go_top.onmouseout = function(){
            clearInterval(timer)
        } 
    }
}