首页 > Web开发 > 详细

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

时间:2015-05-28 17:35:24      阅读:1053      评论:0      收藏:0      [点我收藏+]
$("#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);
 

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

原文:http://www.cnblogs.com/huangjianwu/p/4536369.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!