lib/client/is_visible.js
function _isVisible(start_element, padding) {

	var real_rect,
	    sample,
	    result,
	    rect;

	// Check if the start element is in the document
	if (!elementInDocument(start_element)) {
		return false;
	}

	// Check if the element is explicitly hidden
	if (isHidden(start_element)) {
		return false;
	}

	if (padding == null) {
		padding = 2;
	}

	// Make sure the start element is somewhere on the screen
	real_rect = start_element.getBoundingClientRect();

	rect = {
		bottom : real_rect.bottom + padding,
		right  : real_rect.right  + padding,
		left   : real_rect.left   - padding,
		top    : real_rect.top    - padding
	};

	// Totally underneath the viewport
	if (rect.top > document.documentElement.clientHeight) {
		return false;
	}

	// Totally above the viewport
	if (rect.bottom < 0) {
		return false;
	}

	// Totally left of the viewport
	if (rect.right < 0) {
		return false;
	}

	// Totally right of the viewport
	if (rect.left > document.documentElement.clientWidth) {
		return false;
	}

	result = isElementVisible(start_element);

	if (result) {
		// If no padding is given, we can also check for occlusions
		if (!padding) {
			return elementAtRectPoints(start_element, rect);
		}

		return true;
	} else {
		return false;
	}

	function isElementVisible(element) {

		var context = getViewContext(element),
		    ctx_rect;

		if (!context) {
			return false;
		}

		// Get the context rectangle
		ctx_rect = context.getBoundingClientRect();

		// The current element and the start element
		// both have to collide with the current context rectangle
		// (if the current element equals the start_element we only need
		//  to check the modified rect to the ctx_rect)
		if (   (element == start_element || collides(element, ctx_rect))
			&& collides(rect, ctx_rect)) {

			// If the context element is the document element,
			// no further checks are needed
			if (isDocumentElement(context)) {
				return true;
			}

			// Recursively see if the current context is visible
			return isElementVisible(context);
		}

		return false;
	}
}
function _isVisible(start_element, padding) {

	var real_rect,
	    sample,
	    result,
	    rect;

	// Check if the start element is in the document
	if (!elementInDocument(start_element)) {
		return false;
	}

	// Check if the element is explicitly hidden
	if (isHidden(start_element)) {
		return false;
	}

	if (padding == null) {
		padding = 2;
	}

	// Make sure the start element is somewhere on the screen
	real_rect = start_element.getBoundingClientRect();

	rect = {
		bottom : real_rect.bottom + padding,
		right  : real_rect.right  + padding,
		left   : real_rect.left   - padding,
		top    : real_rect.top    - padding
	};

	// Totally underneath the viewport
	if (rect.top > document.documentElement.clientHeight) {
		return false;
	}

	// Totally above the viewport
	if (rect.bottom < 0) {
		return false;
	}

	// Totally left of the viewport
	if (rect.right < 0) {
		return false;
	}

	// Totally right of the viewport
	if (rect.left > document.documentElement.clientWidth) {
		return false;
	}

	result = isElementVisible(start_element);

	if (result) {
		// If no padding is given, we can also check for occlusions
		if (!padding) {
			return elementAtRectPoints(start_element, rect);
		}

		return true;
	} else {
		return false;
	}

	function isElementVisible(element) {

		var context = getViewContext(element),
		    ctx_rect;

		if (!context) {
			return false;
		}

		// Get the context rectangle
		ctx_rect = context.getBoundingClientRect();

		// The current element and the start element
		// both have to collide with the current context rectangle
		// (if the current element equals the start_element we only need
		//  to check the modified rect to the ctx_rect)
		if (   (element == start_element || collides(element, ctx_rect))
			&& collides(rect, ctx_rect)) {

			// If the context element is the document element,
			// no further checks are needed
			if (isDocumentElement(context)) {
				return true;
			}

			// Recursively see if the current context is visible
			return isElementVisible(context);
		}

		return false;
	}
}
function _isVisible ( start_element , padding ) { var real_rect , sample , result , rect ; // Check if the start element is in the document if ( ! elementInDocument ( start_element ) ) { return false ; } // Check if the element is explicitly hidden if ( isHidden ( start_element ) ) { return false ; } if ( padding == null ) { padding = 2 ; } // Make sure the start element is somewhere on the screen real_rect = start_element . getBoundingClientRect ( ) ; rect = { bottom : real_rect . bottom + padding , right : real_rect . right + padding , left : real_rect . left - padding , top : real_rect . top - padding } ; // Totally underneath the viewport if ( rect . top > document . documentElement . clientHeight ) { return false ; } // Totally above the viewport if ( rect . bottom < 0 ) { return false ; } // Totally left of the viewport if ( rect . right < 0 ) { return false ; } // Totally right of the viewport if ( rect . left > document . documentElement . clientWidth ) { return false ; } result = isElementVisible ( start_element ) ; if ( result ) { // If no padding is given, we can also check for occlusions if ( ! padding ) { return elementAtRectPoints ( start_element , rect ) ; } return true ; } else { return false ; } function isElementVisible ( element ) { var context = getViewContext ( element ) , ctx_rect ; if ( ! context ) { return false ; } // Get the context rectangle ctx_rect = context . getBoundingClientRect ( ) ; // The current element and the start element // both have to collide with the current context rectangle // (if the current element equals the start_element we only need //  to check the modified rect to the ctx_rect) if ( ( element == start_element || collides ( element , ctx_rect ) ) && collides ( rect , ctx_rect ) ) { // If the context element is the document element, // no further checks are needed if ( isDocumentElement ( context ) ) { return true ; } // Recursively see if the current context is visible return isElementVisible ( context ) ; } return false ; } }
The actual visibility checking

@author   Jelle De Loecker   <jelle@develry.be>
@since    1.2.2
@version  1.2.2

@param    {HTMLElement}   element
@param    {Number}        padding

@return   {Boolean}
The actual visibility checking