scullclever
5/27/2014 - 3:42 AM

back-to-top.js

function animateButton() {
    var button = jQuery('#back-to-top');
    var scrollPosition = jQuery(window).scrollTop();
    if (scrollPosition > 300) {
        button.fadeIn();
    } else {
        button.fadeOut();
    }
}

jQuery(function () {
    jQuery('<a id="back-to-top" style="display:none;position:fixed;bottom:10px;left:10px;z-index:99999;cursor:pointer;"><img src="/templates/parfum/images/top-btn.png"></a>')
        .click(function () {
            jQuery('html,body').animate({
                scrollTop: 0
            }, 1000);
            return false;
        })
        .appendTo(jQuery('body'));
});

jQuery(window).resize(animateButton);
jQuery(window).scroll(animateButton);
jQuery(window).load(animateButton);