我收到的错误消息是Cannot read property 'scrollHeight' of null
:
var b = document.getElementById('chat-messages');
b.scrollTop = b.scrollHeight;
var lst = b.scrollTop;
console.log(lst);
b.addEventListener("scroll", function() {
if (b.scrollTop > lst) {
console.log("Greater than Last");
} else {
console.log("Less or equal than last.");
}
lst = b.scrollTop;
});
请帮帮我。谢谢!
答案 0 :(得分:0)
jQuery的正确方法是 -
$('#chat-messages')。prop('scrollHeight')或 $( '#聊天消息')[0] .scrollHeight
希望它有所帮助。