1

As the title says, how can l make that with an easing transition found here : https://gist.github.com/gre/1650294

Please, check below what l wanna' do in pure javascript :

var up = $('#toTop');
$(window).scroll(function() {
    $(this).scrollTop() < 300 ? up.fadeOut() : up.fadeIn();
});
$('#toTop').click(function() {
    $('html, body').stop().animate({
        scrollTop: 0
    }, 2000, 'easeInOutQuart');

jQuery EXEMPLE

And here, my failed attempt in vanilla :

(function() { // reveal arrow
    var arrow = document.getElementById('toTop'),
        myPage = document.querySelectorAll('html, body'),
        revealArrrow = function() {
            var y = window.scrollY;
            y >= 600 ? arrow.className = 'show' : element.classList.remove('show');
        };
    arrow.addEventListener('click', function(e) {
        myPage.animate({
            scrollTop: 0
        }, 2000, 'easeInOutQuart');
    });
    window.addEventListener('scroll', revealArrrow);
})();
EasingFunctions = {
    easeInOutQuart: function(t) {
        return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t
    }
}

VANILLA JS ATTEMPT

Maybe with setTimeout...?

Many thanks.

Joe278
  • 105
  • 1
  • 7

0 Answers0