Here's my implementation using a threshold (4 in this case) to determine if the textarea is scrolled to the bottom (or almost the bottom). I've included the display of the calculated value as well.
The metric used are scrollHeight
, scrollTop
and jQuery's element height()
.
Threshold of '4' works for IE8, Webkit browsers and FF3.5. FF3.5 and Safari (Windows) can go all the way to 0.
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" >
$(function() {
$('#cb').hide(); //hide checkbox
var scrollThreshold = 4; //threshold value
var ta0 = $("#ta");
var ta = $("#ta")[0];
$("#ta").scroll(function(){
var p = ta.scrollHeight - (ta.scrollTop + ta0.height());
$('#pos').val(ta.scrollHeight + ' - (' + ta.scrollTop + ' + ' + ta0.height() + ') = ' + p);
if(p <= scrollThreshold) //if scroll value falls within threshold
$('#cb').show(); //show checkbox
}
);
});
</script>
</head>
<body>
<textarea id="ta" style="width: 200px; height: 100px;">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type specimen book.</textarea>
<br />
<input type="text" id="pos" />
<input type="checkbox" id="cb" />
</body>
</html>
Here's the screenshot for Safari: