Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- windowOnScroll();
- function windowOnScroll() {
- window.addEventListener("scroll", function(e){
- const {scrollHeight,scrollTop,clientHeight} = document.documentElement
- if (scrollTop + clientHeight > scrollHeight -5){
- if(document.querySelectorAll(".post-item").length < document.getElementById("total_count").value) {
- var lastId = document.querySelectorAll(".post-item");
- var lastchild = lastId[lastId.length-1];
- var id=lastchild.getAttribute("id");
- getMoreData(id);
- }
- }
- });
- }
- function getMoreData(id) {
- window.removeEventListener("scroll",windowOnScroll())
- document.querySelector('.ajax-loader').classList.remove("none");
- var formdata=new FormData();
- formdata.append("lastId",id);
- fetch('getMoreData.php',{
- method: 'POST',
- body:formdata
- }).then(function(response){
- response.text().then(function(result){
- setTimeout(function() {
- document.querySelector('.ajax-loader').classList.add("none");
- document.getElementById("post-list").innerHTML+=result;
- windowOnScroll();
- }, 1000);
- })
- }).catch(function(err){
- console.error(err);
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement