0.3.1 • Published 8 years ago

scroll-resize v0.3.1

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

scroll-resize

Throttled window scroll and resize events

Install

npm i scroll-resize

Package on npm

API

constructor(cb, opts)

ArgumentAction
cbthe callback
opts.delayoptional delay, default to 50 ms, min to 25 ms
opts.ignoreoptional ignore, accept scroll or resize, default to undefined
opts.silentif true, no data will be computed and sent to the callback, default to false

The callback cb receive an object with 6 properties — can disabled with opts.silent

ArgumentAction
widththe window innerWidth
heightthe window innerHeight
leftthe window scrollX
topthe window scrollY
rightthe window scrollX + window.innerWidth
bottomthe window scrollY + window.innerHeight
const SR = require('scroll-resize')

function update(data) {
  // {with:.., height:.., left:.., top:.., right:.., bottom:..}
  console.log(data)
}

var sr = new SR(update)

sr.start()

immediate()

Invoke the callbak function cb immediately, cancel the internal throttling if running

Can be used even if the instance was not started yet or is already stopped

start(skip)

Start listening the scroll and|or resize events

By default, the callback fonction cb is called right after the start method is invoked

Set skip to true if you want instead wait the first real event

stop(skip)

Stop listening the events, cancel the internal throttling

By default, the callback fonction cb is called when the stop method is invoked

Set skip to true if you don't want this safer last call

License

MIT