Skip to content

Instantly share code, notes, and snippets.

@larry852
Last active October 9, 2017 04:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larry852/8cd65e8056fe72646d55fd7eeff9add6 to your computer and use it in GitHub Desktop.
Save larry852/8cd65e8056fe72646d55fd7eeff9add6 to your computer and use it in GitHub Desktop.
Lazyload javascripts
// ###########################################################
// Numero de pagina actual
// ###########################################################
var pageNumber = 1;
// ###########################################################
// Deteccion del borde inferior
// ###########################################################
$(function () {
var $win = $(window);
$win.scroll(function () {
if ($win.height() + $win.scrollTop() == $(document).height())
load();
});
});
// ###########################################################
// Carga de nueva pagina de publicaciones
// ###########################################################
function load() {
pageNumber++;
$.ajax({
dataType: "json",
url: base + "SourceBackend/get-page?pageNumber="+pageNumber
}).done(function(data) {
setPostLoad(data);
});
}
// ###########################################################
// Pintado de publiaciones para lazyload
// ###########################################################
function setPostLoad(data) {
for (var i in data) {
var post = data[i];
var fecha = new Date(post.date);
var options = { year: 'numeric', month: 'long', day: 'numeric' };
addPost(post, options, fecha)
}
setMain();
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment