jQuery从入门到熟练(13)

2023-04-24 来源:飞速影视
scrollTop(): 读取/设置滚动条的Y坐标$(document.body).scrollTop() $(document.documentElement).scrollTop(): 读取页面滚动条的Y坐标(兼容 chrome 和 IE)$("body,html").scrollTop(60); 滚动到指定位置(兼容 chrome 和 IE)
<body style="height: 2000px;"><div style="border:1px solid black;width:100px;height:150px;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. his is some text.</div><br><br><br><button>得到scrollTop</button><button>设置scrollTop</button><script src="js/jquery-1.10.1.js"></script><script> //1. 得到div或页面滚动条的坐标 $("#btn1").click(function () { console.log($("div").scrollTop()) // console.log($("html").scrollTop() $("body").scrollTop()) console.log($(document.documentElement).scrollTop() $(document.body).scrollTop()) // 兼容IE/Chrome }) //2. 让div或页面的滚动条滚动到指定位置 $("#btn2").click(function () { $("div").scrollTop(200) $("html,body").scrollTop(300) })</script></body>
相关影视
合作伙伴
本站仅为学习交流之用,所有视频和图片均来自互联网收集而来,版权归原创者所有,本网站只提供web页面服务,并不提供资源存储,也不参与录制、上传
若本站收录的节目无意侵犯了贵司版权,请发邮件(我们会在3个工作日内删除侵权内容,谢谢。)

www.fs94.org-飞速影视 粤ICP备74369512号