arozwalak
9/4/2014 - 6:06 PM

Javascript: Check if element is visible in window

Javascript: Check if element is visible in window

function checkVisible( elm, evalType ) {
	evalType = evalType || "visible";

	var vpH = $(window).height(), // Viewport Height
		st = $(window).scrollTop(), // Scroll Top
		y = $(elm).offset().top,
		elementHeight = $(elm).height();

	if (evalType === "visible") return ((y < (vpH + st)) && (y > (st - elementHeight)));
	if (evalType === "above") return ((y < (vpH + st)));
}