skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
listening for scroll position
description
scroll could be a potential ux interactive that could influence the style of information.
cells
3 total
2 code
state
executed out of order
kernel
Python [conda env:p311] *
language
python
name
conda-env-p311-py
lines of code
44
outputs
1
table of contents
{"kernelspec": {"display_name": "Python [conda env:p311] *", "language": "python", "name": "conda-env-p311-py"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}, "title": "listening for scroll position", "description": "scroll could be a potential ux interactive that could influence the style of information."}
notebook toolbar
Activate
cell ordering
1

listening for scroll position

scroll could be a potential ux interactive that could influence the style of information.

2
%%html
<div id=thing>
    <div>stuff
    </div>
</div>
<style>
#thing {
    max-height: 10rem;
    position: relative;
    &::before {
        position: sticky;
        left: 0;
        top: 0;
        content: "y:" attr(data-scroll-y) ", x:" attr(data-scroll-x);
    }
    overflow-y: auto;
    >div{
        vertical-align: bottom;
        width: 300vw;
        height: 100rem;
            background-color: rgba(255,255,255,var(--scroll-y));
        &::after {
            display: block;
            position: sticky;
            bottom: 0;
            content: "end";
        }
    }
}
</style>
<script>
thing = document.getElementById("thing");
thing.addEventListener("scroll", (event) => {
    let target = event.target;
    let y = (target.scrollTop) / (target.scrollHeight - target.clientHeight);
    let x = (target.scrollLeft) / (target.scrollWidth - target.clientWidth);
    thing.style.setProperty("--scroll-y", y);
    thing.style.setProperty("--scroll-x", x);
    thing.dataset.scrollY = y;
    thing.dataset.scrollX = x
});
</script>
1 outputs.
stuff
3