2.1.0 • Published 2 years ago

@sygnas/scroll-amount v2.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

syg-scroll-amount

ページの最上部、最下部、それ以外の状態を data属性に付与する。

History

  • 2021.11.27 ver.2.1.0
    • ブラウザ版は削除
  • 2021.11.21 ver.2.0.0
    • TypeScriptで書き直した
    • スクロールイベントではなく intersectionObserver を使うようにした
    • スクロール位置検知用エレメントを position:absolut で配置する関係で、position:relative が付与される。

Description

ページ最上部にいる時はdata-scroll-amount属性に「top」を付与します。 最下部は「bottom」、それ以外は「no-top」「no-bottom」を付与します。

固定ヘッダーの出し入れや、ページトップボタンの出し入れなどに使います。

Usage

Install

npm install --save @sygnas/scroll-amount

html / JS / css

<header class="js-scroll-amount scroll-amount">
    出し入れしたい内容
</header>
import ScrollAmount from '@sygnas/scroll-amount';

const target1 = new ScrollAmount('.js-scroll-amount', {
    // Options
});
.scroll-amount{
    transition: .2s;

    &[data-scroll-amount ~= "top"]{
        transform: translateY(-40px);
    }
}

Attributes

属性 data-scroll-amount にステータスが書き出されます。

<header class="js-scroll-amount scroll-amount" data-scroll-amount="top no-bottom">
namecomment
topスクロール位置が最上部
not-topスクロール位置が最上部ではない
bottomスクロール位置が最下部
not-bottomスクロール位置が最下部ではない

Options

optiondefaultcomment
offsetTop70pxスクロール位置がこの値より上ならページ最上部と判断
offsetBottom70pxスクロール位置がこの値より下ならページ最下部と判断
onTopfunction最上部にスクロールした時に実行
onNotTopfunction最上部から離れた時に実行
onBottomfunction最下部にスクロールした時に実行
onNotBottomfunction最下部から離れた時に実行

License

MIT

2.0.3

2 years ago

2.0.2

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

1.2.2

5 years ago

1.1.2

6 years ago

1.1.1

6 years ago