当前位置: 首页 > news >正文

柞水县住房和城乡建设局网站四川省造价工程信息网

柞水县住房和城乡建设局网站,四川省造价工程信息网,海口网站运营托管费用,旅游网站建设步骤有时候我们会遇到监听iframe或document的滚动事件不起作用的情况#xff0c;在排除代码写错的情况下#xff0c;我们应该考虑此时的document是否可以滑动。 1、为什么document不能监听滑动? 就很奇怪#xff0c;明明页面时有滚动条的#xff0c;为什么说document不可滑动…有时候我们会遇到监听iframe或document的滚动事件不起作用的情况在排除代码写错的情况下我们应该考虑此时的document是否可以滑动。 1、为什么document不能监听滑动? 就很奇怪明明页面时有滚动条的为什么说document不可滑动呢 因为有的document.scrollingElement本身就不可滑动可滑动的是它的子元素而不document.scrollingElement本身document.scrollingElement本身没有溢出问题它的子元素有溢出问题并产生的scrollbar 展示document不能滚动的DEMO !DOCTYPE html htmlheadmeta charsetutf-8 /titledocument不能滑动滑动的是它的子元素/titlestylehtml,body {padding: 0;margin: 0;}/style/headbodydiv stylewidth: 100%;height: 100vh;overflow: auto;h1这是1号标题/h1p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph2这是2号标题/h2p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph3这是3号标题/h3p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph4这是4号标题/h4p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph5这是5号标题/h5p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph6这是6号标题/h6p这是一个段落。/pp这是一个段落。/pp这是一个段落。/p/div/bodyscriptwindow.onload function() {document.onscroll function() {//获取滚动条的位置var scrollTop document.documentElement.scrollTop ||document.body.scrollTop;console.log(滚动条的位置, scrollTop);};};/script/html2、什么是document.scrollingElement scrollingElementDocument 的只读属性返回滚动文档的 Element 对象的引用。在标准模式下这是文档的根元素 document.documentElement。 当在怪异模式下scrollingElement 属性返回 HTML body 元素若不存在返回 null。 3、为什么要有document.scrollingElement 众所周知获取浏览器高度是有兼容的当我们需要设置滚动条的位置时一般情况下 document.documentElement.scrollTop 100; // PC端 document.body.scrollTop 100; // 移动端 当有了document.scrollingElement后我们就不需要处理兼容问题了两端通用 document.scrollingElement 100; // 两端通用 4、用js代码测试元素是否可滑动 // 判断是否可滑动 function isScrollable(ele) {const hasScrollableContent ele.scrollHeight ele.clientHeight;const overflowYStyle window.getComputedStyle(ele).overflowY;const isOverflowHidden overflowYStyle.indexOf(hidden) ! -1;return hasScrollableContent !isOverflowHidden; } 5、监听iframe的滚动案例 5.1 document可滑动 demo.html !DOCTYPE html htmlheadmeta charsetutf-8 /titleiframe或document监听滚动事件/title/headbodyiframe idmyframeId src./iframe.html width90% height200pxp你的浏览器不支持iframes。/p/iframe/bodyscript// 判断是否可滑动function isScrollable(ele) {const hasScrollableContent ele.scrollHeight ele.clientHeight;const overflowYStyle window.getComputedStyle(ele).overflowY;const isOverflowHidden overflowYStyle.indexOf(hidden) ! -1;return hasScrollableContent !isOverflowHidden;}window.onload function() {let result isScrollable(document.scrollingElement);console.log(demo是否可滑动, result)var frameWidow document.getElementById(myframeId).contentWindow;console.log(frameWidow);// 两端通用// frameWidow.document.scrollingElement.scrollTop 100// 适用PC端// frameWidow.document.documentElement.scrollTop 200// 适用移动端// frameWidow.document.body.scrollTop 300// scrollTo()方法frameWidow.scrollTo(0, 400)//监听frameWidow.onscroll function() {//获取滚动条的位置var scrollTop frameWidow.document.documentElement.scrollTop ||frameWidow.document.body.scrollTop;console.log(frame滚动条的位置, scrollTop);// window.pageYOffset (支持IE9)// var scrollTop frameWidow.pageYOffset;// var scrollTop frameWidow.document.scrollingElement.scrollTop;};};/script/htmlframe.html !DOCTYPE html htmlheadmeta charsetutf-8 /titleiframe或document监听滚动事件/titlestylehtml,body {padding: 0;margin: 0;}/style/headbodyh1这是1号标题/h1p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph2这是2号标题/h2p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph3这是3号标题/h3p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph4这是4号标题/h4p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph5这是5号标题/h5p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph6这是6号标题/h6p这是一个段落。/pp这是一个段落。/pp这是一个段落。/p/bodyscript// 判断是否可滑动function isScrollable(ele) {const hasScrollableContent ele.scrollHeight ele.clientHeight;const overflowYStyle window.getComputedStyle(ele).overflowY;const isOverflowHidden overflowYStyle.indexOf(hidden) ! -1;return hasScrollableContent !isOverflowHidden;}window.onload function() {console.log(document.scrollingElement)let result isScrollable(document.scrollingElement);console.log(frame是否可滑动, result)setTimeout(() {// 两端通用// document.scrollingElement.scrollTop 100// 适用PC端// frameWidow.document.documentElement.scrollTop 200// 适用移动端// frameWidow.document.body.scrollTop 300// scrollTo()方法// frameWidow.scrollTo(0, 400)})};/script/html5.2 document本身不可滑动 demo.html 不作修改frame.html 修改如下 !DOCTYPE html htmlheadmeta charsetutf-8 /titleiframe或document监听滚动事件/titlestylehtml,body {padding: 0;margin: 0;}/style/headbodydiv stylewidth: 100%;height: 100vh;overflow: auto;h1这是1号标题/h1p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph2这是2号标题/h2p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph3这是3号标题/h3p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph4这是4号标题/h4p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph5这是5号标题/h5p这是一个段落。/pp这是一个段落。/pp这是一个段落。/ph6这是6号标题/h6p这是一个段落。/pp这是一个段落。/pp这是一个段落。/p/div/bodyscript// 判断是否可滑动function isScrollable(ele) {const hasScrollableContent ele.scrollHeight ele.clientHeight;const overflowYStyle window.getComputedStyle(ele).overflowY;const isOverflowHidden overflowYStyle.indexOf(hidden) ! -1;return hasScrollableContent !isOverflowHidden;}window.onload function() {console.log(document.scrollingElement)let result isScrollable(document.scrollingElement);console.log(frame是否可滑动, result)setTimeout(() {// 两端通用// document.scrollingElement.scrollTop 100// 适用PC端// frameWidow.document.documentElement.scrollTop 200// 适用移动端// frameWidow.document.body.scrollTop 300// scrollTo()方法// frameWidow.scrollTo(0, 400)})};/script/html
http://www.hkea.cn/news/14358667/

相关文章:

  • 知识网站有哪些百度seo推广
  • 官方网站面膜做微商做家政网站公司名称
  • 德州建设街小学网站中英文网站开发公司
  • 网站建设怎么提需求设计之家网站怎么样
  • 上海专业网站建站品上海小程序开发合肥
  • 建网站做cpa如何用域名做邮箱 网站
  • 网站建设方案总结网站推广和网络推广
  • wordpress怎样静态化seo就业哪家好
  • 淄博易宝网站建设小企业网站建设在哪里
  • 乐清定制网站建设电话网站关键词优化有用吗
  • 企业网站建设选题依据百度竞价 百度流量 网站权重
  • 如何查找网站死链手机网站开发者模式
  • 宁波正规网站建设使用方法周至做网站
  • 什么是销售型网站陕西省建设执业资格注册管理中心网站
  • 精品课程 网站建设质量自己做app的网站
  • 安庆什么网站好小事做营销型网站建设汽车
  • 公司想做一个网站陕西十二建设有限公司网站
  • asp net做购物网站网上哪里可以免费打广告
  • 衡阳网站排名优化费用网页设计代码完整版
  • 免费建网站的app建网站需要的费用
  • 网站建设合理的流程做电商平台网站有哪些内容
  • 河南开封网站建设seo的描述正确
  • 国家外汇管理局网站怎么做报告网页qq登录保护不再开启入口
  • 公司做的网站费用计入什么科目做网站横幅用什么软件好
  • 别人做的网站如何要回服务器网络空间购买
  • 做设计兼职的网站有哪些下载app最新版
  • 自己建公司网站可以嘛网站站内链接怎么做
  • 哪家公司设计网站好谷歌google官网下载
  • 邯郸做seo网站优化群晖做网站服务器会卡吗
  • 在线模版下载网站南昌网站建设方案