Created
February 28, 2014 14:06
-
-
Save guillemcanal/9271672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* {padding: 0; margin:0; color: #444} | |
#main { | |
position : absolute; | |
top:5px; | |
left:5px; | |
right:5px; | |
bottom:5px; | |
border:1px solid #E5E5E5; | |
padding: 5px; | |
overflow-y:auto; | |
} | |
ul { | |
list-style:none | |
} | |
li { | |
display: block; | |
border: 1px solid #E5E5E5; | |
width: 100px; | |
height:100px; | |
margin:5px; | |
background: white; | |
padding: 5px; | |
float: left | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<script src="http://jashkenas.github.io/underscore/underscore-min.js"></script> | |
<meta charset="UTF-8"> | |
<title>Test</title> | |
</head> | |
<body> | |
<div id="main"> | |
<ul id="list"></ul> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var | |
main = document.querySelector("#main") | |
, list = document.querySelector("#list") | |
, triggerHeight = 800 | |
, loadMore = function(parent) { | |
var fragment = document.createDocumentFragment(); | |
for ( var e = 0; e < 500; e++ ) { | |
fragment.appendChild( document.createElement("li") ) | |
} | |
parent.appendChild( fragment.cloneNode(true) ) | |
} | |
, infiniteScroll = _.debounce(function(evt) { | |
if(evt.target.scrollTop + evt.target.offsetHeight + triggerHeight >= evt.target.scrollHeight) { | |
console.log("loading more...") | |
loadMore(main) | |
} | |
console.log("scrolled") | |
}, 400, false) | |
, resizeFn = _.debounce(function(evt) { | |
console.log("resized") | |
}, 400, false) | |
main.addEventListener("scroll", infiniteScroll, false) | |
window.addEventListener("resize", resizeFn) | |
loadMore(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment