javascript - Horizontal AJAX posts loader, detect when scrollbar reaches the end -
i've set div (#reviewspostscont) overflow-x:scroll, want load posts ajax cant't detect when scrollbar gets right end. down below code have far, can't understand whats wrong it. in advance, matt
$('#reviewspostscont').scroll(function(){ var $this = $(this); scrollpercentage = 100 * $(this).scrollleft() / ($('#reviewspostscont').width() - $(this).width()); if (scrollpercentage == 100){ alert('end!'); // test code, ajax } });
the issue around how calculate total scroll width. have added jsfiddle. basically, instead of:
scrollpercentage = 100 * $(this).scrollleft() / ($('#reviewspostscont').width() - $(this).width());
you should have:
scrollpercentage = 100 * $(this).scrollleft() / ($(this)[0].scrollwidth - $(this).width());
Comments
Post a Comment