Hello.
Are there any plugins under jQuery to send an Ajax request when a certain block (say with id = "load_on_screen") appears in the view area on the screen?
Or how to do it yourself? Where to dig? scrollUp is not suitable.
Hello.
Are there any plugins under jQuery to send an Ajax request when a certain block (say with id = "load_on_screen") appears in the view area on the screen?
Or how to do it yourself? Where to dig? scrollUp is not suitable.
function inWindow(s){ var scrollTop = $(window).scrollTop(); var windowHeight = $(window).height(); var currentEls = $(s); var result = []; var offset = currentEls.offset(); if(scrollTop <= offset.top && (currentEls.height() + offset.top) < (scrollTop + windowHeight)) return true; return false; } var boxesInWindow = inWindow("#sc-2"); console.log(boxesInWindow); $(document).scroll(function () { if(inWindow("#sc-2")) { console.log('1'); } }); .sc-1 { width:100%; height:500px; background:red } .sc-2 { width:100%; height:300px; background:green } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="sc-1" class="sc-1"> </div> <div id="sc-2" class="sc-2"> </div> In general, there is a library lazy load as an option to use it
Source: https://ru.stackoverflow.com/questions/631959/
All Articles