var counter = 2,
    limit = 20;
function onScroll() {
    
    console.log(Math.round($(window).scrollTop()+50) + " >= " + ($(document).height() -  $(window).height()) + " " + counter);
    
  //  alert(Math.round($(window).scrollTop()+50) + " >= " + ($(document).height() -  $(window).height()) + " " + counter);
    
    //$("#tabelenco").append(""  + Math.round($(window).scrollTop()+100) + " >= " + ($(document).height() -  $(window).height()) + " " + counter + "
");
    
     if(Math.round($(window).scrollTop()+100) >= ($(document).height() - $(window).height()) && counter == 2)
    {
        counter = 1;
        appendData();
       
    }
     
     if ($(window).scrollTop() < 202)
     {
      $("#definisci").hide();
     } 
     
      if ( $(window).scrollTop() > 202)
      {
       $("#definisci").fadeIn("slow");
      }
     
}
function appendData() {
    $.ajax({
        type: "get",
        url: "funzione_elenco.php?l=K&&limit=" + limit,
        success: function(o) {
            $("#tabelenco").append(o);
            counter = 2; limit += 20;
            
        }
    });
    
    
    
}
$(document.body).on("touchmove", onScroll), $(window).on("scroll", onScroll);