i've got a Tricky problem...for now i'm working offline but soon i will get data from a web service. Now when i scroll down a javascript listener push other data on a global variable...
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height()) {
alert("CARICAAAA!");
//window.gvariabile è la variabile globale che prenderà i risultati
//new data li prenderò dal web service
var newdata=["cocco","pera","melone","anguria","cocco","pera","melone","anguria","cocco","pera","melone","anguria","cocco","pera","melone","anguria","cocco","pera","melone","anguria"];
window.gvariabile.push(newdata);
alert(gvariabile.length);
for(var i=0;i<newdata.length;i++){
div.setAttribute('id2', 'd'+count);
div.innerHTML="<img src='img/eng_ico.jpg' class='logo'> <h3>"+newdata[i]+" "+count+"</h3><p>Dettagli</p><hr class='hor'>";
}
// alert("fuffa2");
//rimetti lo scroll ad inizio pagina
window.scrollTo(0, 1);
}
});
the problem is that each time i load new data the lenght of the global variable increment of 1...not 20...(Except the first time that load correctly other 20 data)
and this is where i set for the first time the global variable:
function onDeviceReady() {
//qua all'avvio carichiamo i primi risultati
var risultati =["cocco","pera","melone","anguria","cocco","pera","melone","anguria","cocco","pera","melone","anguria","cocco","pera","melone","anguria","cocco","pera","melone","anguria"];
window.gvariabile =risultati;
for(var i=0;i< risultati.length;i++){
var div = document.getElementById('d'+i);
div.setAttribute('id2', 'dd'+i);
div.innerHTML="<img src='img/eng_ico.jpg' class='logo'> <h3>"+risultati[i]+" "+i+"</h3><p>Dettagli</p><hr class='hor'>";
div.addEventListener("click", redirect_click(i), false);
}
}