簡單版—返回頂部

撐船的擺渡人發表於2018-05-29

頁面右下角返回頂部

html



<div class="sriLink">
    <div class="back_top" onclick="window.scrollTo(0,0);return false" style="display: none;">
        <a href="javascript:void(0);"></a>
    </div>
    <div class="go_aboutUs">
        <a href="/aboutus" target="_blank">關於<br>我們</a>
    </div>
    <div class="go_feedBack">
        <a href="javascript:void(0);" target="_blank">意見<br>反饋</a>
    </div>
</div>

css


.sriLink{
    position: fixed;
    right: 50%;
    margin-right: -665px;
    bottom: 90px;
    z-index: 100;
}
.sriLink a{
    display: block;
    width: 50px;
    height: 50px;
    background: #eceded;
    text-align: center;
    padding-top: 8px;
    color: white;
    border-radius: 3px;
    margin-top: 5px;
    line-height: 16px;
}
.sriLink .back_top a {
    background: #e4e4e4 url(../image/back_top.png) no-repeat center;
}

js


/*滾動事件*/
window.addEventListener(`scroll`,function(e){
    var t = document.documentElement.scrollTop || document.body.scrollTop;
    if(t > 400 ){
        $(`.back_top`).show();
    }else{
        $(`.back_top`).hide();
    }
})
/*全域性頁面中間內容高度*/
$().ready(function(){
    var Height = $(window).height();
    var h = (Height - 212)+`px` //頭部和底部總高為212
   $(`.sriContainer`).css(`min-height`,h);
})

相關文章