Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript-enabled overscrolling

One can make smooth scrolling animations to go from one part of a webpage to another. Nowadays, some browsers (e.g. Chrome for Mac) support "overscrolling", and often scrolling involves overscrolling.

So the traditional scrolling animations look quite artificial without overscrolling. Is there a way to overscroll a webpage with JavaScript to enhance the traditional scrolling animation?

like image 789
Randomblue Avatar asked Oct 06 '22 20:10

Randomblue


1 Answers

Yes you can make a bounce back animation.

I assume you meant to say bounce back https://ux.stackexchange.com/questions/13183/name-of-the-touch-ui-overscroll-feature

I just built a quick / buggy one.

var threshold = 400,
    wrap = document.getElementById('wrap'),
    wrapHeight = wrap.offsetHeight,
    pageHeight = (wrapHeight + threshold);

wrap.style.height = pageHeight+'px';

window.addEventListener('scroll', function(){
    var pageY = window.pageYOffset;

    if (pageY > wrapHeight - threshold*1.5) {
        wrap.style.height = wrapHeight+'px';
    }
    if (wrap.offsetHeight === wrapHeight) {
        if ((pageY > wrapHeight - threshold*2.5) ) {
            wrap.style.height = pageHeight+'px';
        }
    }
});

also https://github.com/andrewrjones/jquery.bounceback

the basic idea behind my code: you make the page larger to accommodate the animation. then you reset the page height after scrolling away from the bottom.

to actually make the animation you need to add: #wrap { -webkit-transition: height .5s; }

like image 150
Chris Avatar answered Oct 10 '22 02:10

Chris