Here, my implementation uses a threshold (in this case 4) to determine if the text area scrolls to the bottom (or almost to the bottom). I also turned on the display of the calculated value.
Used metric: scrollHeight, scrollTopand jQuery element height().
Threshold "4" works for browsers IE8, Webkit and FF3.5. FF3.5 and Safari (Windows) can go up 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();
var scrollThreshold = 4;
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)
$('#cb').show();
}
);
});
</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 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 is a screenshot for Safari:
In Safari http://i46.tinypic.com/nej3ft.jpg
source
share