jQuery使用scrollTop获取div标签的滚动条已滚动高度(jQuery版本1.6+时,用prop()方法代替attr()方法)

$("#content").append('<div>' + data.msg + '</div>'+.'<br>');
$('#content').attr({ scrollTop: $('#content').attr('scrollHeight') });

//jQuery版本1.6+时,用prop()方法代替attr()方法:【重点,否则获取不到】
$('#content').prop({ scrollTop: $('#content').prop('scrollHeight') });
 
 
例子:
//加上动画效果
$('#content').animate({ scrollTop: $('#content').attr('scrollHeight') }, 1000);
//1.6+
$('#content').animate({ scrollTop: $('#content').prop('scrollHeight') }, 1000);
 
原文地址:https://www.cnblogs.com/huangjianwu/p/4536369.html