<ul class="listview"></ul>
<span class="polyfill-notice">The polyfill is in use</span>
<script>
	if (!('IntersectionObserver' in window))
		document.body.classList.add('polyfill');
</script>
<script src="https://cdn.rawgit.com/surma-dump/IntersectionObserver/polyfill/polyfill/intersectionobserver-polyfill.js"></script>

body {
	margin: 0;
	font-family: sans-serif;
	font-size: 14px;
	line-height: 21px;
}

p {
	margin: 0;
	margin-bottom: 21px;
}
p:last-child {
	margin-bottom: 0;
}

.listview {
	list-style: none;
	max-width: 500px;
	margin: 0 auto;
	padding: 21px 20px 21px;
	box-sizing: border-box;
}
@media screen and (min-width: 540px) {
	.listview {
		padding-left: 0;
		padding-right: 0;
	}
}

.listview__item {
	display: -webkit-box;
	display: -ms-flexbox;
	display: flex;
	margin-bottom: 21px;
	font-family: georgia, serif;
}

.listview__item__id {
	-webkit-box-flex: 0;
	    -ms-flex: 0 0 auto;
	        flex: 0 0 auto;
	width: 40px;
	margin-right: 20px;
	text-align: right;
	color: #333;
	font-style: italic;
}
.listview__item__id::before {
	content: '#';
}

.listview__item__content {
	-webkit-box-flex: 1;
	    -ms-flex: 1 1 auto;
	        flex: 1 1 auto;
}

.listview__item.sentinel {
	border: 1px solid orange;
}

.listview::after {
	content: 'Loading...';
	text-align: center;
	text-transform: uppercase;
	font-size: 28px;
	line-height: 42px;
	display: none;
}
.listview.loading::after {
	display: block;
}

.polyfill-notice {
	position: fixed;
	top: 0;
	left: 0;
	padding: 10px;
	background-color: orange;
	color: #fff;
	font-family: sans-serif;
	display: none;	
}
.polyfill .polyfill-notice {
	display: block;
}
var 
	pageSize = 10,
	sentinel = {
		el: null,
		set: function(el) {
			this.el = el;
			this.el.classList.add('sentinel');
			sentinelObserver.observe(this.el);
		},
		unset: function() {
			if (!this.el)
				return;
			sentinelObserver.unobserve(this.el);
			this.el.classList.remove('sentinel');
			this.el = null;
		}
	},
	sentinelListener = function(entries) {
		console.log(entries);
		
		sentinel.unset();
		listView.classList.add('loading');
		nextPage().then(() => {
			updateSentinel();
			listView.classList.remove('loading');
		});
	},
	updateSentinel = function() {
		sentinel.set(listView.children[listView.children.length - pageSize]);
	},
	nextPage = function() {
		return loadNextPage().then((items) => {
			listView.insertAdjacentHTML(
				'beforeend', 
				items.map(item => `
					<li class="listview__item">
						<span class="listview__item__id">${item.id}</span>
						<div class="listview__item__content">
							<p>${item.text}</p>
						</div>
					</li>
				`).join('')
			);
		});
	},
	loadNextPage = (function() {
		var 
			pageNumber = 0,
			placeholders = [
				'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.',
				'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.',
				'Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi, condimentum sed, commodo vitae, ornare sit amet, wisi. Aenean fermentum, elit eget tincidunt condimentum, eros ipsum rutrum orci, sagittis tempus lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus, tortor neque egestas augue, eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi, tincidunt quis, accumsan porttitor, facilisis luctus, metus'
			]
		;
		return function () {
			console.log(`Loading page #${pageNumber}`);
			return new Promise(function(resolve, reject) {
				var items = [];
				for (var id = pageNumber*pageSize, lastId = id + pageSize - 1; id <= lastId; ++id) {
					items.push({
						id: id,
						text: placeholders[getRandomInRange(0, placeholders.length - 1)]
					})
				}
				pageNumber++;
				setTimeout(function() { resolve(items); }, getRandomInRange(500, 4000));
			});
		}
	})(),
	getRandomInRange = function(min, max) { // http://thenewcode.com/82/Recipes-for-Randomness-in-JavaScript
		return Math.floor(Math.random() * (max - min + 1)) + min;
	},
	listView = document.querySelector('.listview'),
	sentinelObserver = new IntersectionObserver(sentinelListener, {threshold: 1})
;
 
nextPage().then(() => { 
	nextPage().then(updateSentinel);
});
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.