scroll-lazy

1.0.3 • Public • Published

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

Dependents (0)

Package Sidebar

Install

npm i scroll-lazy

Weekly Downloads

12

Version

1.0.3

License

MIT

Last publish

Collaborators

  • yusukeshibata