购物车
登陆 / 注册
微信扫码登陆

推荐手册

jQuery 教程手册(新) >> jQuery手册
其他教程参考

jQuery scrollTop() 方法

jQuery scrollTop() 方法
scrollTop() 方法设置或返回被选元素的垂直滚动条位置。
蹊下 蹊下 更新时间:2019-02-26 15:48:24

jQuery scrollTop() 方法

定义和用法

scrollTop() 方法设置或返回被选元素的垂直滚动条位置。

提示:当滚动条位于最顶部时,位置是 0。

当用于返回位置时:

该方法返回第一个匹配元素的滚动条的垂直位置。

当用于设置位置时:

该方法设置所有匹配元素的滚动条的垂直位置。

语法

返回垂直滚动条位置:

$(selector).scrollTop()

设置垂直滚动条位置:

$(selector).scrollTop(position)
参数描述
position 规定以像素为单位的垂直滚动条位置。    

实例

<script>
$(document).ready(function(){
  $("button").click(function(){
    alert($("div").scrollTop()+" px");
  });
});
</script>
</head>
<body>

<div style="border:1px solid black;width:100px;height:150px;overflow:auto">
This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text. This is some text.</div><br>
<button>返回垂直滚动条的位置</button>

运行实例 »

点击 "运行实例" 按钮查看在线实例

效果图:

网站导航
标签地图
学习路径
视频教程
开发软件
旗下子站
技术文章
文档工具
关于我们
企业合作
人才招聘
联系我们
讲师招募
QQ交流群
QQ官方交流群
微信公众号
微信公众号