返回顶部按钮效果实现

HTML:button按钮也可以

<div class="return top_btn ng-scope" style="display: block;"></div>

css:

.return {
    position: fixed;
    right: 2%;
    bottom: 4.6%;
    width: 48px;
    height: 48px;
    background: url(../images/up_top@2x.png);
    background-size: 100% 100%;
    cursor: pointer;
}

 

js:

        $(document).ready(function () {
            $(".top_btn").hide();
            $(function () {
                $(window).scroll(function () {
                    if ($(window).scrollTop() > 100) {
                        $(".top_btn").fadeIn(1500);
                    } else {
                        $(".top_btn").fadeOut(1500);
                    }
                });
                //当点击跳转链接后,回到页面顶部位置
                $(".top_btn").click(function () {
                    $('body,html').animate({
                            scrollTop: 0
                        },
                        1000);
                    return false;
                });
            });
        });

 

posted @ 2018-10-12 16:44  大稳·杨  阅读(1580)  评论(0编辑  收藏  举报