打开页面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,如需转载请自行联系原作者






相关文章
|
小程序
小程序-uniapp:实现锚点连接/锚点跳转
小程序-uniapp:实现锚点连接/锚点跳转
571 0
|
2月前
|
JavaScript
Elementplus淡入淡出效果,头部顶栏如何设置文字隐藏效果,默认图标如何收缩,icons如何通过类进行替换,侧边栏如何添加阴影,右边如何设置高度,侧边栏如何设置阴影,如何让icon与文字
Elementplus淡入淡出效果,头部顶栏如何设置文字隐藏效果,默认图标如何收缩,icons如何通过类进行替换,侧边栏如何添加阴影,右边如何设置高度,侧边栏如何设置阴影,如何让icon与文字
vitepress如何配置右上角的小两侧标志,利用nav标签进行修改,右侧边栏如何设置成自动弹出水平框,让原先隐藏的框能够显示出来
vitepress如何配置右上角的小两侧标志,利用nav标签进行修改,右侧边栏如何设置成自动弹出水平框,让原先隐藏的框能够显示出来
scrollIntoView()定位元素显示导致页面上移解决方法?
scrollIntoView()定位元素显示导致页面上移解决方法?
448 0
|
4月前
|
iOS开发
ios中,输入框获得焦点时,页面输入框被遮盖,定位的元素位置错乱
ios中,输入框获得焦点时,页面输入框被遮盖,定位的元素位置错乱
64 1
|
10月前
div层定位在网页右下角
div层定位在网页右下角
41 0
layui列表页滚动时弹出窗无法居中的解决方案
layui列表页滚动时弹出窗无法居中的解决方案
112 0
点击图片或者鼠标划过切换样式的另一种写法
点击图片或者鼠标划过切换样式的另一种写法
65 0
|
JavaScript
div 滚动条自动保持在底部
div 滚动条自动保持在底部
386 0
小程序 - swiper除了左右切换还有上下滚动超出屏幕的内容
本来呢,我是有专门整理小程序恶心bug的文章的,每次只要添加汇总就好, 但是呢,鉴于这个问题的恶心程度,所以我把他单独拿出来说了。 ——————————————--------------------------------------------------产品经理都说恶心的需求---------...
2365 0