Return to Snippet

Revision: 17973
at September 18, 2009 09:27 by jodm


Initial Code
function checkInScreen(objId, blnWholeElement, blnBorders) {

	// THE OBJECT
	obj = document.getElementById(objId);

	// GET THE TOP AND LEFT POSITION OF THE ELEMENT
	var arrPositions = findPosition(obj);
	var intTop = arrPositions[1]; 
	
	
	// GET THE SCREEN DIMENTIONS
	var arrScreenDimentions = getScreenDimentions();
	var intAvailableHeight = arrScreenDimentions[2];
		
	// GET THE HEIGHT OF THE ELEMENT
	var objHeight = getStyle(objId, 'height');
	
	// REMOVE THE 'PX' FROM THE END OF THE HEIGHT
	var strHeight = objHeight.substr(0, objHeight.length - 2);
	
	// ROUND THE HEIGHT UP
	var intHeight = Math.ceil(strHeight * 1);
	
	// ADJUST THE AVAILABLE HEIGHT SPACE AND ADD THE HEIGHT 
	if(blnWholeElement) { intTop = intTop + intHeight; }
	
	
	// GET THE SIZE OF THE TOP AND BOTTOM BORDERS
	var strBorderTopWidth = getStyle(objId, 'border-top-width');
	var strBorderBottomWidth = getStyle(objId, 'border-bottom-width');
	
	var intBorderTopWidth = strBorderTopWidth.substr(0, strBorderTopWidth.length - 2);
	var intBorderBottomWidth = strBorderBottomWidth.substr(0, strBorderBottomWidth.length - 2);
	
	var intBorders = (intBorderTopWidth * 1) + (intBorderBottomWidth * 1);
	
	if(blnBorders) { intTop = intTop + intBorders; }
	
	
	// CHECK IF IN VIEWABLE AREA...
	if(intTop > intAvailableHeight) {
		 alert( 'NOT ALL OF THE ELEMENT IS IN THE VIEWABLE AREA ');
		return false;
	} else {
	 	 alert( 'THE ELEMENT IS VIEWABLE ');
		return true;
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Javascript checkInScreen

Initial Tags

                                

Initial Language
JavaScript