$(function() {

            $(window).scroll(function() {
                if ($(window).scrollTop() > 200) {
                    $('#gotop').fadeIn(500);
                } else {
                    $("#gotop").fadeOut(500);
                }
            });
            $("#gotop").click(function() {
                $('body,html').animate({
                    scrollTop: '0'
                }, 300);
                return false; //防止默认事件行为
            })

        })
<div class="public-gotop" id="gotop">回到顶部</div>

 

相关文章: