$("#scrollUp").removeClass("show");
$htmlBody = $("html, body");
$(window).scroll(function() {
    if ($(this).scrollTop() > 500) {
        $("#scrollUp").addClass("show");
        $("#scrollUp").click(function(event) {
            event.preventDefault();
            $htmlBody.animate({
                scrollTop: 0
            }, 1500);
        });
    } else {
        $("#scrollUp").removeClass("show");
    }
});
  
  $("#scrollUp").removeClass("show");
$("#scrollUp").click(function(event) {
    event.preventDefault();
    $("html, body").animate({
        scrollTop: 0
    }, 1500);
});
$(window).scroll(function() {
    $("#scrollUp").toggleClass("show", ($(this).scrollTop() > 500));
});