读值

1)

window.pageYOffset==window.scrollY

it returns the number of pixels the document is currently scrolled along the vertical axis

2)

scrollElm.scrollTop

gets or sets the number of pixels that an element's content is scrolled vertically.

注意这里的scrollElm代表可滑动的元素,测试元素是否可以滑动可以用如下方法:

设置值

// Set the number of pixels scrolled.
scrollElm.scrollTop = intValue;

代码示例

<div id="container"><div id="scroller"><p>Far out in the uncharted backwaters of the unfashionable endof the western spiral arm of the Galaxy lies a small unregardedyellow sun. Orbiting this at a distance of roughly ninety-two millionmiles is an utterly insignificant little blue green planet whoseape-descended life forms are so amazingly primitive that they stillthink digital watches are a pretty neat idea.</p></div>
</div><div id="output">scrollTop: 0</div>
const scroller = document.querySelector("#scroller");
const output = document.querySelector("#output");scroller.addEventListener("scroll", event => {output.textContent = `scrollTop: ${scroller.scrollTop}`;
});

scroll事件的解释:

代码示例

    var pc = document.getElementById('page-container')pc.addEventListener('scroll', function(e) {window.parent.postMessage("scrollTop_zh:" + pc.scrollTop, "*")});

这是一个静态的元素高.

还有一个容易混的scrollHeight

document或iframe监听滑动失败的问题

https://blog.csdn.net/u010087338/article/details/121712846https://blog.csdn.net/u010087338/article/details/121712846

js滑动操作之-pageYOffset,scrollTop,offsetHeight,scrollHeight相关推荐

  1. Js——ScrollTop、ScrollHeight、ClientHeight、OffsetHeight汇总

    一直对ScrollTop.ScrollHeight.ClientHeight.OffsetHeight这些内容傻傻分不清楚,今天整体下. scrollHeight scrollHeight含有scro ...

  2. top、postop、scrolltop、scrollHeight、offsetHeight

    网页可见区域宽:document.body.clientWidth;    网页可见区域高:document.body.clientHeight;    网页可见区域高:document.body.o ...

  3. clientHeight offsetHeight scrollHeight offsetTop scrollTop

    文章目录 各属性详解 实现 offsetParent.offsetLeft/offsetTop深度剖析 element.offsetParent 定义 祖先元素中不存在定位元素 webkit内核.Fi ...

  4. html5 scrollheight,JavaScript之scrollTop、scrollHeight、offsetTop、offsetHeight等属性学习笔记...

    全文参考:https://github.com/iuap-design/blog/issues/38 .MDN clientHeight,只读 clientHeight可以用公式 CSS height ...

  5. html 滚动条 scrolltop scrollheight,浅谈JavaScript中scrollTop、scrollHeight、offsetTop、offsetHeight...

    浅谈JavaScript中scrollTop.scrollHeight.offsetTop.offsetHeight 发布时间:2020-07-17 09:27:20 来源:亿速云 阅读:223 作者 ...

  6. html 滚动条 scrolltop scrollheight,JavaScript之scrollTop、scrollHeight、offsetTop、offsetHeight等属性学习笔记...

    全文参考:https://github.com/iuap-design/blog/issues/38 .MDN clientHeight,只读 clientHeight可以用公式 CSS height ...

  7. offsetTop,offsetHeight,scrollHeight,scrollTop的区别

    offsetTop,offsetHeight,scrollHeight,scrollTop,这些属性曾经困扰了我很长很长很长时间. 今天花点功夫,彻底把他们搞清楚了. 假设 obj 为某个 HTML ...

  8. 滚动条三要素scrollTop clientHeight scrollHeight

    插件 https://github.com/inuyaksa/jquery.nicescroll <!DOCTYPE html> <html><head><m ...

  9. js实现操作等待提示loading……

    js实现操作等待功能,防止重复提交,界面友好,底部为灰色遮罩层,防止用户重复操作. 先看效果图:   接着看js代码: 1 //关闭等待窗口 2 function closeWaiting() { 3 ...

最新文章

  1. 合工大计算机研究生毕业工资,合肥工业大学2019届薪酬统计
  2. php taint安装失败,PHP Taint – 一个用来检测XSS漏洞的扩展
  3. IDEA、Sublime、Eclipse、VSCode 常用快捷键整合
  4. python正则表达式判断数字_Python机器学习之手写数字辨识及正则表达式
  5. [Tools] JD-GUI(Java Decompiler)
  6. 字符串里面的单词反转
  7. 如何修改WSS站点的主菜单
  8. FastAPI用户安全性解决方案
  9. 【comsol快速入门】
  10. pandas读取excel遇见空值的处理
  11. 阿里云调用api配置access_key
  12. 使用Ezy-Slice插件实现类似Beat Saber的模型切割效果(一)
  13. 8000401a错误解决方案(Excel)
  14. Linux之V4L2驱动框架
  15. 程序员 怎样成为自由职业_如何成为一名成功的自由程序员
  16. CentOS7配置本地yum源 和yum源服务器
  17. pymssql连接sql server报错:pymssql._pymssql.OperationalError
  18. LaTeX中对矩阵加行属性名称和列属性名称
  19. 渗透攻防必备工具(基础篇,收藏起来)
  20. HTML网页部分怎么与上面隔开,HTML网页制作讲义.ppt

热门文章

  1. Android高级控件(一)——ListView绑定CheckBox实现全选,增加和删除等功能
  2. 【树莓派4B】如何烧录新的系统
  3. 容联云AI问鼎“千言数据集—实体链指评测“,持续打造知识语义计算能力
  4. Hive实现时间滑动窗口计算
  5. 深度学习在计算机视觉领域图像应用总结
  6. 谷粒商城--商品发布--笔记九
  7. 直播带货系统,带货直播系统中发布商品的逻辑处理流程
  8. 组态王网页服务器,组态王6.55WEB全新发布详细步骤
  9. DML语言(数据库操作语言)和DQL语言(数据库查询语言)
  10. 外呼系统《OpenSIPS2.4代理FreeSwitch》(2022版)