Skip to content

Instantly share code, notes, and snippets.

@almazka987
Last active July 30, 2019 09:11
Show Gist options
  • Save almazka987/af05a59473a8bad2cda3683ca67ea710 to your computer and use it in GitHub Desktop.
Save almazka987/af05a59473a8bad2cda3683ca67ea710 to your computer and use it in GitHub Desktop.
jQuery Scroll Back To Top Button Arrow

jQuery Scroll Back To Top Button Arrow

html:

<div id="alio_to_top"><a href="#"></a></div>

css:

#alio_to_top a {
    display: none;
    z-index: 999;
    position: fixed;
    bottom: 5px;
    right: 3%;
    width: 73px;
    opacity: 0;
    transition: opacity .5s;
    height: 123px;
    background: url("#{$img-path}/rocket-arrow.png") no-repeat;
    background-size: contain;

    &.active {
        display: block;
        animation: slideInUp 0.7s;
        opacity: .8;
    }

    &:hover {
        opacity: 1;
    }
}

scripts.js:

// Scroll to Top Button
$(window).scroll(function () {
    if ($(this).scrollTop() > 300) {
        $('#alio_to_top a').css('display', 'block').addClass('active');
    } else {
        $('#alio_to_top a').fadeOut("slow", function() {
            $(this).removeClass("active");
        });
    }
});

$('#alio_to_top a').click(function () {
    $('body,html').animate({
        scrollTop: 0
    }, 500);
    return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment