UNPKG

scroll-lazy

Version:
37 lines (34 loc) 912 B
var Lazy = require('../') document.addEventListener('DOMContentLoaded', function(event) { Lazy .on(function(next) { console.log('lazy') document.getElementById('loading').style.opacity = 1 setTimeout(function() { var element = document.createElement('div') element.style.background = '#ccc' element.style.margin = 10 element.style.height = Math.random() * 2000 document.body.appendChild(element) document.getElementById('loading').style.opacity = 0 next() },1000) }) .watch({ threshold:function() { return 4 }, 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 }, }) })