zoukankan      html  css  js  c++  java
  • js获取页面元素距离浏览器工作区顶端的距离

     网页被卷起来的高度/宽度(即浏览器滚动条滚动后隐藏的页面内容高度)

    (javascript)        document.documentElement.scrollTop //firefox

    (javascript)        document.documentElement.scrollLeft //firefox

    (javascript)        document.body.scrollTop //IE

    (javascript)        document.body.scrollLeft //IE

    (jqurey)             $(window).scrollTop() 

    (jqurey)             $(window).scrollLeft()

     网页工作区域的高度和宽度  

    (javascript)       document.documentElement.clientHeight// IE firefox       

    (jqurey)             $(window).height()

     元素距离文档顶端和左边的偏移值  

    (javascript)        DOM元素对象.offsetTop //IE firefox

    (javascript)        DOM元素对象.offsetLeft //IE firefox

    (jqurey)             jq对象.offset().top

    (jqurey)             jq对象.offset().left

    获取页面元素距离浏览器工作区顶端的距离

     页面元素距离浏览器工作区顶端的距离  =  元素距离文档顶端偏移值  -   网页被卷起来的高度  

    即:

     页面元素距离浏览器工作区顶端的距离  DOM元素对象.offsetTop  -  document.documentElement.scrollTop 

  • 相关阅读:
    luogu P1144 最短路计数
    codevs 1006 等差数列
    luogu P2419 [USACO08JAN]牛大赛Cow Contest
    luogu cogs 选数
    luogu P1186玛丽卡
    leetcode[69]Sqrt(x)
    leetcode[70]Climbing Stairs
    leetcode[71]Simplify Path
    leetcode[72]Edit Distance
    leetcode[73]Set Matrix Zeroes
  • 原文地址:https://www.cnblogs.com/yangAL/p/5807599.html
Copyright © 2011-2022 走看看