Требуется расстояние до HTML-документа за вычетом высоты экрана:
var html = document.documentElement;
var doc_height = Math.max(html.clientHeight, html.scrollHeight, html.offsetHeight);
var height = (screen.height > doc_height ? screen.height-doc_height : 0); //if the space exists, else return 0