Skip to content

Truly independent web browser

2.3 KB
Raw Blame
<!DOCTYPE html>
<script src="include.js"></script>
<style>
    .scroller {
        width: 200px;
        height: 200px;
        overflow: scroll;
        scroll-snap-type: y mandatory;
    }
    .item {
        width: 100%;
        height: 200px;
        scroll-snap-align: start;
    }
</style>
<div id="scroller" class="scroller">
    <div class="item"></div>
    <div style="height: 60px"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
</div>
<div id="equally-spaced" class="scroller">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
</div>
<script>
    promiseTest(async () => {
        const scroller = document.getElementById("scroller");
        const equallySpaced = document.getElementById("equally-spaced");

        await animationFrame();
        await animationFrame();

        const stepsSettled = (target, wheelY, deltaY, stepCount) =>
            scrollSettled(target, async () => {
                // A wheel promise waits for its snap animation. Send every step before awaiting them so that
                // animation completion cannot let the gesture's input deadline pass between steps.
                const steps = [];
                for (let step = 0; step < stepCount; ++step)
                    steps.push(internals.wheel(50, wheelY, 0, deltaY));
                await Promise.all(steps);
            });

        // Steps that arrive while a snap position is being scrolled to select the same position.
        await stepsSettled(scroller, 50, 10, 2);
        println(`scroll offset after two small steps: ${scroller.scrollLeft},${scroller.scrollTop}`);

        // Steps whose deltas ask for a longer scroll keep selecting snap positions further along.
        await stepsSettled(scroller, 50, 150, 2);
        println(`scroll offset after two large steps: ${scroller.scrollLeft},${scroller.scrollTop}`);

        // A step whose delta is the distance between neighboring snap positions asks for the next one exactly, so it
        // must not skip over the position it lands on.
        await stepsSettled(equallySpaced, 300, 200, 2);
        println(`scroll offset after two steps of one snap position: ${equallySpaced.scrollLeft},${equallySpaced.scrollTop}`);
    });
</script>