discourse/app/assets/javascripts/discourse/lib/is-element-in-viewport.js.es6

12 lines
319 B
JavaScript

export default function (element) {
if (element instanceof jQuery) { element = element[0]; }
const $window = $(window),
rect = element.getBoundingClientRect();
return rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= $window.height() &&
rect.right <= $window.width();
}