I was trying to implement a horizontal scroll inside a div. My question is how can I detect the end of the horizontal scroll?
I tried something like this
$(function() {
var scrollLeftPrev=0;
$('#scrollquestion').scroll( function() {
var newScrollLeft=$('#scrollquestion').scrollLeft();
if(scrollLeftPrev===newScrollLeft){
alert('right end');
}
if(newScrollLeft===0){
alert('left end');
}
console.log($('#scrollquestion').width());
console.log(newScrollLeft);
scrollLeftPrev=newScrollLeft;
});
});
left end alert works, since it will become 0 for all the device sizes. For right end, it depends on the device size.
JS Fiddle : http://jsfiddle.net/arunslb123/trxe4n3u/