Socket
Socket
Sign inDemoInstall

@sygnas/scroll-amount

Package Overview
Dependencies
0
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @sygnas/scroll-amount

Add scrolling state(top / not-top / bottom / not-bottom)


Version published
Maintainers
1
Created

Readme

Source

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

Keywords

FAQs

Last updated on 27 Nov 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc