Use scrollWidth
and width
along with your leftscrollwidth
to get the difference. In your case there is offset of 8
so it will give the difference of 8
it may be because of your padding or margin.
var $elem=$('#scrollquestion');
var newScrollLeft = $elem.scrollLeft(),
width=$elem.width(),
scrollWidth=$elem.get(0).scrollWidth;
var offset=8;
if (scrollWidth- newScrollLeft-width==offset) {
alert('right end');
}
Live Demo
Use the outerWidth() to get the offset including the width like,
var $elem=$('#scrollquestion');
var newScrollLeft = $elem.scrollLeft(),
width=$elem.outerWidth(),
scrollWidth=$elem.get(0).scrollWidth;
if (scrollWidth-newScrollLeft==width) {
alert('right end');
}
Another Demo without using offset
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…