- 0133技术站
- 联系QQ:18840023
- QQ交流群

- 微信公众号

jQuery scrollLeft() 方法
定义和用法
scrollLeft() 方法设置或返回被选元素的水平滚动条位置。
提示:当滚动条位于最左侧时,位置是 0。
当用于返回位置时:
该方法返回第一个匹配元素的滚动条的水平位置。
当用于设置位置时:
该方法设置所有匹配元素的滚动条的水平位置。
语法
返回水平滚动条位置:
$(selector).scrollLeft()
设置水平滚动条位置:
$(selector).scrollLeft(position)
参数 | 描述 |
position | 规定以像素为单位的水平滚动条位置。 |
<script> $(document).ready(function(){ $("button").click(function(){ alert($("div").scrollLeft()+" px"); }); }); </script> </head> <body> <div style="border:1px solid black;width:100px;height:130px;overflow:auto"> The longest word in the english dictionary is: pneumonoultramicroscopicsilicovolcanoconiosis. </div><br> <button>返回水平滚动条的位置</button>
点击 "运行实例" 按钮查看在线实例
效果图:
推荐手册