window.addEventListener('DOMContentLoaded', function () {

    document.getElementById('backToButton').style.visibility = 'hidden';

    document.getElementById('backToButton').addEventListener('transitionend', function () {
        if (document.getElementById('backToButton').className !== 'view') {
            document.getElementById('backToButton').style.visibility = 'hidden';
        }
    });

    window.addEventListener('scroll', function () {
        if (0 < window.scrollY) {
            document.getElementById('backToButton').style.visibility = 'visible';
            document.getElementById('backToButton').classList.add('view');
        } else {
            document.getElementById('backToButton').classList.remove('view');
        }
    });
});