Skip to content

alpacachen/sticky-change

Repository files navigation

sticky-change

NPM Package Build Size

watching HTMLElement's sticky state, without scroll events.

play on stackblitz (a bug from stackblitz, when in build-in browser, can not use IntersectionObserver API normally, so just click open in new window)

Usage

pure

<head>
    <script src="./dist/index.js"></script>
</head>
<div id="page-title" style="position: sticky; top: 30px">Page Title</div>
<script>
    new WatchSticky(
            document.getElementById('page-title'), 
            null, 
            () => {
                document.getElementById('page-title').classList.toggle('shadow', true)
            },
            () => {
                document.getElementById('page-title').classList.toggle('shadow', false)
            }
    )
</script>

npm

npm i sticky-change

import {WatchSticky} from 'sticky-change'

new WatchSticky(ref, null, stickyCb, unstickyCb)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published