"In AEM editor mode, #ContentWrapper <div> gets dynamically injected from 'ContentFrame.js' file. You can located this file at /libs/cq/gui/components/authoring/editors/clientlibs/core/js/ContentFrame.js (this is the path in AEM 6.4 not sure about earlier versions). This file has a functions 'getDocumentHeight' which returns maximum of "(doc.body.scrollHeight, doc.documentElement.scrollHeight, doc.body.offsetHeight, doc.documentElement.offsetHeight)" and causes page height in edit mode to go infinite. Change this function to return "Math.min()" instead of "Math.max()" to accurately calculate height of the pages in AEM edit mode.
DO NOT CHANGE anything in the original file located under '/libs' instead create an overlay '/apps/cq/gui/components/authoring/editors/clientlibs/core/js/ContentFrame.js' and make this change."