var pages = [page_1, page_2, page_3, page_4, page_5]; var backupPages=new Array(); var totalPage = "page_" + pages.length; $("<div id='" + totalPage + "'>" + pages.pop() + "</div>").prependTo($("#fullContainer")); $("#fullContainer").scroll(function () { // top if ($(this).scrollTop() === 0 && pages.length) { console.log("up"); var stringLoad = "page_" + pages.length; $("<div id='" + stringLoad + "'>" + pages.pop() + "</div>").prependTo($("#fullContainer")); //remove element at 2nd index $('#fullContainer').children().slice(2).remove() } if ($(this).scrollTop() >= $(this)[0].scrollHeight - document.body.offsetHeight) { console.log("down"+$('#fullContainer div:last-child').attr('id')); } });
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript" src="Scripts/jquery-2.1.0.js"></script> <script> $(window).scroll(function () { if ($(window).scrollTop() + $(window).height() == $(document).height()) { var div = '<div style="height: 100px; background-color:#ccc;">This Div just Got Appended</div>'; $('body').append(div); } }); </script> </head> <body> <div style="height: 1000px">Scroll down!</div> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)