Grazie Enzaccio ma avevo già risolto simile al tuo ma senza offsetHeight che è ottimo ma non ci avevo pensato ho risolto con window.screen.height