top在html5里什么意思,html中的scrolltop是什么意思

scrolltop是jQuery中的一个方法,它可以设置

元素中滚动条的垂直偏移量,基本的用法是:

scrollTop() 方法返或设置匹配元素的滚动条的垂直位置。

scroll top offset 指的是滚动条相对于其顶部的偏移。

如果该方法未设置参数,则返以像素计的相对滚动条顶部的偏移。

工具原料:jQuery、编辑器、浏览器

1、在一个有内容的div中是吸纳设置滚动条的偏移量和获取偏移量的值,代码如下:

$(document).ready(function(){

$(".btn1").click(function(){

$("div").scrollTop(100);

});

$(".btn2").click(function(){

alert($("div").scrollTop()+" px");

});

});

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. 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. 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. 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.

把 scroll top offset 设置为 100px

获得 scroll top offset

2、运行的效果如下:

7d642f94df4321d4ea39f4316b519d18.png

点击设置为100px后的效果:

575d3cad8373815f542290ce2f8bb39b.png

点击获取值的效果:

47dc3803669533a9030e8ee113ecd637.png