打开页面div滚动条定位(别用锚点)

简介:

打开页面div滚动条定位(别用锚点)



wKiom1jcsHCygTdUAABFInYNIsw241.png-wh_50

wKioL1jcsHGDrarqAABL43tnuTM537.png-wh_50





来啦!客官久等了!!!!! 上代码:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html>
<html xmlns= "http://www.w3.org/1999/xhtml" >
<head>
<title>打开页面div滚动条定位</title>
<meta http-equiv= "Content-Type"  content= "text/html; charset=utf-8"  />
<script src= "jquery-1.8.2.min.js" ></script>
<script>
$(document).ready( function (){
     var  goTop = $( "#div-top" ).position().top;
     $( "#content" ).animate({scrollTop: goTop}, 0);
});
</script>
</head>
 
<body>
<div id= "content"  style= "width:300px;height:500px;background:#ccc;overflow:auto;" >
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360"  id= "div-top" ><div style= "width:200px;height:50px;background:#ff0" >这里此时正在to  do  something</div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
<div style= "border:1px solid #f00;width:250px;height:100px;margin-top:10px;background:#360" ><div style= "width:200px;height:50px;background:#ff0" ></div></div>
</div>
</body>
</html>







营养成分:

animate() 方法执行 CSS 属性集的自定义动画。

position() 方法返回匹配元素相对于父元素的位置(偏移)。该方法返回的对象包含两个整型属性:top 和 left,以像素计



(The End)




   本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/1911771,如需转载请自行联系原作者






相关文章
|
16天前
VSCode如何自动换行,右侧换行间距长度,隐藏右侧代码预览(Minimap代码缩略图滚动条),比对代码差异窗口也自动换行
VSCode如何自动换行,右侧换行间距长度,隐藏右侧代码预览(Minimap代码缩略图滚动条),比对代码差异窗口也自动换行
|
Web App开发 JavaScript 程序员
如何去掉或者修改网页中的遮罩层,DIV等元素?
起因: 前几天女友在查资料写文章,打开一个网页,发现网页的被一个半透明的遮罩层给覆盖了(一个已经过期的组织活动 的网页,H5就将它遮盖了),就来问我怎么弄。
1568 0
|
6月前
|
前端开发 JavaScript 容器
JavaScrpit如何实现弹出遮罩层后将页面固定到当前位置且无法继续滚动
JavaScrpit如何实现弹出遮罩层后将页面固定到当前位置且无法继续滚动
29 0
|
4月前
|
iOS开发
ios中,输入框获得焦点时,页面输入框被遮盖,定位的元素位置错乱
ios中,输入框获得焦点时,页面输入框被遮盖,定位的元素位置错乱
35 1
|
9月前
layui列表页滚动时弹出窗无法居中的解决方案
layui列表页滚动时弹出窗无法居中的解决方案
81 0
点击图片或者鼠标划过切换样式的另一种写法
点击图片或者鼠标划过切换样式的另一种写法
57 0
|
JavaScript
Vue组件中表格文字内容太长,自动变省略号,鼠标悬浮上去显示全称。
Vue组件中表格文字内容太长,自动变省略号,鼠标悬浮上去显示全称。
556 0
|
JSON 数据格式
底部弹出PopupWindow+地址三级联动,多问题全面分析,详细注释
底部弹出PopupWindow+地址三级联动,多问题全面分析,详细注释
140 0
底部弹出PopupWindow+地址三级联动,多问题全面分析,详细注释
iframe框根据内容自适应高度(100%可用)
iframe框根据内容自适应高度(100%可用)
892 0

热门文章

最新文章