Javascript checkInScreen


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function checkInScreen(objId, blnWholeElement, blnBorders) {
  2.  
  3. // THE OBJECT
  4. obj = document.getElementById(objId);
  5.  
  6. // GET THE TOP AND LEFT POSITION OF THE ELEMENT
  7. var arrPositions = findPosition(obj);
  8. var intTop = arrPositions[1];
  9.  
  10.  
  11. // GET THE SCREEN DIMENTIONS
  12. var arrScreenDimentions = getScreenDimentions();
  13. var intAvailableHeight = arrScreenDimentions[2];
  14.  
  15. // GET THE HEIGHT OF THE ELEMENT
  16. var objHeight = getStyle(objId, 'height');
  17.  
  18. // REMOVE THE 'PX' FROM THE END OF THE HEIGHT
  19. var strHeight = objHeight.substr(0, objHeight.length - 2);
  20.  
  21. // ROUND THE HEIGHT UP
  22. var intHeight = Math.ceil(strHeight * 1);
  23.  
  24. // ADJUST THE AVAILABLE HEIGHT SPACE AND ADD THE HEIGHT
  25. if(blnWholeElement) { intTop = intTop + intHeight; }
  26.  
  27.  
  28. // GET THE SIZE OF THE TOP AND BOTTOM BORDERS
  29. var strBorderTopWidth = getStyle(objId, 'border-top-width');
  30. var strBorderBottomWidth = getStyle(objId, 'border-bottom-width');
  31.  
  32. var intBorderTopWidth = strBorderTopWidth.substr(0, strBorderTopWidth.length - 2);
  33. var intBorderBottomWidth = strBorderBottomWidth.substr(0, strBorderBottomWidth.length - 2);
  34.  
  35. var intBorders = (intBorderTopWidth * 1) + (intBorderBottomWidth * 1);
  36.  
  37. if(blnBorders) { intTop = intTop + intBorders; }
  38.  
  39.  
  40. // CHECK IF IN VIEWABLE AREA...
  41. if(intTop > intAvailableHeight) {
  42. alert( 'NOT ALL OF THE ELEMENT IS IN THE VIEWABLE AREA ');
  43. return false;
  44. } else {
  45. alert( 'THE ELEMENT IS VIEWABLE ');
  46. return true;
  47. }
  48. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.