Calling Ajax script on onscroll event of an element:
In the example below element “adListContainer” is an div, on onscroll event of which an ajax function
is called to load the next set of records.
It is required that the function be called only at the end of scrolling or scroll bottom.
var oAdList = document.getElementById("adListContainer"); var iVisibleHeight = oAdList.clientHeight; var iScrollableHeight = oAdList.scrollHeight; var iScrollTop = oAdList.scrollTop; if((iScrollTop+iVisibleHeight) == iScrollableHeight){ // call the ajax function to load the next set of ads showNextSetofAds(); }
Categories: Javascript