你能否告诉我为什么scrollTop
无效。实际上我想把焦点放在那里,而我给命令预先添加文本。
实际上,焦点是文本前置文本的顶部。我需要重点应该保持不变。
当我在前面添加文本时,焦点会变为行顶。
$("#contend").scroll(function () {
if ($(this).scrollTop() === 0) {
alert("ssss");
$("#pre").prepend(" Distinguished service of a high degree to Australia or to humanity at largefjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf adasda sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf adasda sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf adasda sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf adasda sdflkjsdlfjsldfj sdfsjdflsf adasda sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf adasda sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf adasda sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf sdfjsflsj sdflkjsdlfjsldfj sdfsjdflsf adasda");
alert($("#pre")[0].scrollHeight)
$("#pre").prependTo("#contend");
document.getElementById("content").scrollTop = $("#pre")[0].scrollHeight
}
});
$("#contend").scroll(function () {
if ($('#contend').scrollTop() >= $('#contend')[0].scrollHeight - document.body.offsetHeight) {
$("#pre").html('');
}
});
答案 0 :(得分:0)
我认为
$(this).scrollTop()
永远不会是0
尝试改变
if ($(this).scrollTop() === 0) {
到
if( $(this).scrollTop() < 1) {