undefinedio / stash

Wordpress stack with gulp, capistrano, timber + twig and webpack
MIT License
10 stars 6 forks source link

implement smooth scrolling like roji.be #42

Closed koraysels closed 8 years ago

simonpeters commented 8 years ago

eeuw

VincentPeters commented 8 years ago
document.onmousewheel = function () {
        customScroll();
    };

//Smoothscrolling for the masses!
$(function () {
    var $window = $(window);

    document.onmousewheel = function () {
        customScroll();
    };

    if (document.addEventListener) {
        document.addEventListener('DOMMouseScroll', customScroll, false);
    }

    function customScroll(event) {

        var delta = 0;

        if (!event) {
            event = window.event;
        }

        if (event.wheelDelta) {
            delta = event.wheelDelta / 120;
        } else if (event.detail) {
            delta = -event.detail / 3;
        }

        if (delta) {

            var scrollTop = $window.scrollTop();
            var finScroll = scrollTop - parseInt(delta * 70);

            TweenMax.to($window, 0.3, {
                scrollTo: {y: finScroll, autoKill: true},
                ease: Power4.easeOut,
                autoKill: true,
                overwrite: 5,
            });
        }

        if (event.preventDefault) {
            event.preventDefault();
        }

        event.returnValue = false;
    }
});
simonpeters commented 8 years ago

https://www.reddit.com/r/webdev/comments/47n9ph/psa_dont_use_smooth_scroll_scriptsplugins_on_your/