滚动条定位
来源:互联网 发布:淘宝宝贝卖点模板 编辑:程序博客网 时间:2024/04/30 14:16
首先来一个例子:
<html> <head> <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".btn1").click(function(){ $("div").scrollTop(100); }); $(".btn2").click(function(){ alert($("div").scrollTop()+" px"); }); }); </script> </head> <body> <div style="border:1px solid black;width:200px;height:200px;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. 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. </div> <button class="btn1">把 scroll top offset 设置为 100px</button> <br /> <button class="btn2">获得 scroll top offset</button> </body> </html>上述例子的链接:http://www.w3school.com.cn/tiy/t.asp?f=jquery_css_scrolltop_set
注:滚动条所在的div必须有overflow属性且value不能为hidden
请看复杂情况:
这种情况主要用于使用了滚动条插件的情况,一眼看去不知道那个div在滚动,随意找一个div是不能正常工作的。
如果想加入一点动画效果,可以适应animate方法
var scrollTop = 100;$(".form").parent().parent().animate("scrollTop: "+ scrollTop +"'px'", 400);从form向上找两个parent就是带有overflow属性的滚动条所在的容器
0 0
- 滚动条定位控制
- 滚动条定位控制
- flex定位滚动条
- javascript滚动条定位
- 滚动条定位
- 解决滚动条定位
- 网页滚动条定位(vs2005)
- 怎么定位滚动条位置
- 定位滚动条的问题
- 定位滚动条的位置
- HTML页面滚动条定位
- QTextEdit中滚动条定位
- 滚动条滚动,treeview动态加载,滚动条定位
- 关于网页滚动条的定位
- vb.net ,右侧滚动条定位
- 刷新页面滚动条定位.net
- 页面刷新后滚动条重新定位
- Asp.net 中listbox 滚动条定位
- Json解析实例Tomcat服务器
- 简单编程(十六)编写递归方法返回x和y的最大公约数
- 数据结构:图--拓扑排序
- HDU 2604 Queuing 递推
- Android Canvas绘图详解
- 滚动条定位
- BubbleShader 0.2
- Ubuntu学习札记【三】Ubuntu 12.04下安装JDK1.8.0_25
- 绘制几何图形——使用android.graphics类
- 简单编程(十七)对小数n进行四舍五入返回一个整数
- 【分治】POJ-2255 Tree Recovery
- 数据结构:图的遍历--深度优先、广度优先
- 科教及探索节目摘要
- hdu 4463Outlets题解(Dijkstra)