avatar
check if element is in viewport Javascript
const elIsVisibleInViewport = (el, partiallyVisible = false) => {
	const { top, left, bottom, right } = el.getBoundingClientRect();
	const { innerHeight, innerWidth } = window;
	return partiallyVisible
		? ((top > 0 && top < innerHeight) ||
			(bottom > 0 && bottom < innerHeight)) &&
				((left > 0 && left < innerWidth)  ||
					(right > 0 && right < innerWidth))
		: top >= 0 && left >= 0 && bottom <= innerHeight && right <= innerWidth;	
};


elIsVisibleInViewport(el); // For the case, false => not fully visible
elIsVisibleInViewport(el, true) // In the opposite, true => partially visible
You need to login to do this manipulation!