Skip to content

Instantly share code, notes, and snippets.

@pedrohugorm
Last active December 12, 2017 17:21
Show Gist options
  • Save pedrohugorm/6e204afac417874b88060806d49a1816 to your computer and use it in GitHub Desktop.
Save pedrohugorm/6e204afac417874b88060806d49a1816 to your computer and use it in GitHub Desktop.
Infinite Scroll Performance Problem
function isElementInViewport (rect) {
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
)
}
function hideIfNotVisible(o){
if(o.visible === false) $(o.el).children().remove();
return o
}
function createFakeSpace(o){
$(o.el).css('height', o.rect.height)
return o
}
$('.lead-table .lead-row')
.map((i, el) => {el, rect: el.getBoundingClientRect()})
.map((i, o) => {
o.visible = isElementInViewport(o.rect)
return o
})
.map((i, o) => {
hideIfNotVisible(o)
createFakeSpace(o)
return o
})
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment