I have figured out 'dynamical load' and 'synchronized scroll of two divs' separately, but now I'd like to combine them. Simple HTML:
<div id="div1">
<div class="div1_cell"> One line </div>
<div class="div1_cell"> One line </div>
...
</div>
<div id="div2" onscroll=SyncScroll(this)>
<div class="div2_cell"> One line </div>
<div class="div2_cell"> One line </div>
...
</div>
Synchronized scroll works with this :
function SyncScroll(div) {
var div1 = document.getElementById('div1');
div1.scrollTop = div.scrollTop;
}
And I'm trying to load the page dynamically with:
$(document).ready(function () {
size_div1 = $("#div1 .div1_cell").size();
size_div2 = $("#div2 .div2_cell").size();
x=5;
$('#div1 .div1_cell:lt('+x+')').show();
$('#div2 .div2_cell:lt('+x+')').show();
div2 = document.getElementById('div2')
div2.onscroll = function() {
if(div2.scrollTop + div2.clientHeight == div2.scrollHeight) {
x=(x+5 <= size_div1) ? x+5 : size_div1;
$('#div1 .div1_cell:lt('+x+')').show();
x=(x+5 <= size_div2) ? x+5 : size_div2;
$('#div2 .div2_cell:lt('+x+')').show();
}
}
});
It does show up the initial size of the two divs (here 5) and it does load more data on scroll, but I've got two problems:
- it loads the rest of the data at once, not gradually adding 5 more every time I hit bottom,
- syncscroll stopped working and dynamical load only works for div2, while div1 is frozen
This is my very first attempt in Javascript needed for a larger project, I'm sure it looks messy. I would appreciate your help. Thanks!