码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-05-28 17:36:51      阅读:131      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!