1.1.1 • Published 8 years ago

syg-scroll-amount v1.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

syg-scroll-amount

Set data attribute according to status at the time of page scroll(top / not-top / bottom / not-bottom ..)

ページスクロール時にステータスに応じたdata属性を付与する(top / not-top / bottom / not-bottom ..)。

Description

スクロールに応じた固定ヘッダーの出し入れなどに使います。 ブラウザがページスクロールした時に、「ページ最上部にいる」「ページ最上部にいない」などのステータスのdata属性をエレメントに付与します。

Usage

Install

npm install syg-scroll-amount

html / JS / css

<header class="js-scroll-amount scroll-amount">
    ...menu...
</header>
import ScrollAmount from 'syg-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 pin">
namecomment
topスクロール位置が最上部
not-topスクロール位置が最上部ではない
bottomスクロール位置が最下部
not-bottomスクロール位置が最下部ではない

Options

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

License

MIT

1.1.1

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago