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);
 
posted @ 2015-05-28 16:58  KenmuHuang  阅读(2344)  评论(0编辑  收藏  举报
如果您看完本篇博文,觉得对您有所收获,请点击右下角的 [推荐]
如果您想转载,请注明出处(原创内容,请尊重个人劳动成果)
如果您有任何意见或建议,欢迎留言
感谢您的阅读,敬请关注我的后续博客文章