/* Если высота окна + высота прокрутки больше или равны высоте всего документа и ajax-запрос в настоящий момент не выполняется, то запускаем ajax-запрос */ if ($(window).scrollTop() + $(window).height() >= $(document).height() - 200) {} 

Closed due to the fact that the question is not clear to the participants of the Air , 0xdb , cheops , Suvitruf , default locale 10 May '18 at 9:19 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 3
    The jQuery source is there, so they are gradually excavated and understood. - SmInc
  • There are a lot of different expressions, you need to clarify which part you find difficult to translate into vanilla JavaScript. - default locale

3 answers 3

You can try this:

 const windowScroll = () => { return window.scrollY || window.pageYOffset || document.documentElement.scrollTop; } const windowHeight = () => { return window.innerHeight; } const documentHeight = () => { return document.documentElement.offsetHeight } window.addEventListener('scroll', () => { if ( windowHeight() + windowScroll() >= documentHeight() - 200 ) { console.log('true') } }) 
 html { height: 2000px; } 

     if (window.innerHeight + window.pageYOffset == document.documentElement.scrollHeight) {} 

    • conditions are not equivalent - Grundy

     if (window.pageYOffset + window.innerHeight >= document.documentElement.clientHeight - 200) 

    • Do you know what you can fix and restore a deleted answer? - Igor
    • document.documentElement.clientHeight should it be equal to the height of the window ?? - Alice Kus