NueveReinas

HTML

<a href="#" class="arriba">Arriba</a>

CSS

html {
    min-height:200%;
}

.arriba {
    position:fixed;
    background:red;
    color:white;
    opacity:0;
}

JavaScript

// SCROLLTESTER START //
$('<h1 id="st" style="position: fixed; right: 25px; bottom: 25px;"></h1>').insertAfter('body');

$(window).scroll(function () {
  var st = $(window).scrollTop();
  var scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();

  $('#st').replaceWith('<h1 id="st" style="position: fixed; right: 25px; bottom: 25px;">scrollTop: ' + st + '<br>scrollBottom: ' + scrollBottom + '</h1>');
});
// SCROLLTESTER END //

$(window).scroll(function(){
    
    var scrollBottom = $(document).height() - $(window).height() - $(window).scrollTop();
    
if (scrollBottom < 200) {
$('.arriba').css("opacity","1");
} else {
$('.arriba').css("opacity","0");
}
}); 
$('.arriba').click(function(){
$("html, body").animate({ scrollTop: 0 }, 700);
return false;
});