scroll-lazy

v1.0.3
Event emitter for lazy scrolling.
lazy scroll javascript npm

lazy.js

Install: npm install scroll-lazy

Event emitter for lazy scrolling.

// Create
var Lazy = require('scroll-lazy')

var lazy = Lazy
.on(function(next) {
    // ...do something
    next() // lazy checker resume on next
})
.watch()
// stop lazy
lazy.off()

With option.

// this is default option setting
lazy.watch({
    check:function(callback) {
        callback(null,this.body()-this.container() < this.scroll()+this.threshold())
    },
    threshold:function() {
        return 10
    },
    scroll:function() {
        return document.body.scrollTop
    },
    body:function() {
        var height = document.body.offsetHeight
        var style = getComputedStyle(document.body)
        height += parseInt(style.marginTop) + parseInt(style.marginBottom)
        return height
    },
    container:function() {
        return window.innerHeight
    },
})

Option

threshold

default:10

container

default:window.innerHeight

scroll

default:document.body.scrollTop

body

default:document.body.outerHeight

License

MIT

npm i scroll-lazy

Metadata

  • MIT
  • Whatever
  • Yusuke Shibata
  • released 7/12/2016

Downloads

Maintainers