Voici ma mise en œuvre en utilisant un seuil (4 dans ce cas) pour déterminer si la zone de texte fait défiler ed au fond (ou presque au fond). J'ai également inclus l'affichage de la valeur calculée.
La métrique utilisée est scrollHeight
, scrollTop
et l'élément jQuery height()
.
Le seuil de '4' fonctionne pour IE8, les navigateurs Webkit et FF3.5. FF3.5 et Safari (Windows) peuvent aller tout le chemin à 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>
Voici la capture d'écran pour Safari:
On Safari http://i46.tinypic.com/nej3ft.jpg
essayé cela, il ne fonctionnera pas car la largeur est d'environ 400+ et quand je défile à la toute fin ça me donne 288. – allenskd