Simple Infinite Scrolling with jQuery

function _getContent() { var next = $('#next'), href = next.attr('href'); $.get(href).done(function(data) { next.after(data); next.remove(); }); } function _scroll() { $('div').scroll(function() { var $this = $(this), height = this.scrollHeight - $this.height(), scroll = $this.scrollTop(), scrollEnd = (scroll >= height); if (scrollEnd) { var nextContent = _getContent(); $this.append(nextContent); } }); } $(function() { _scroll() });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.