zoukankan      html  css  js  c++  java
  • 获取dom位置信息

     
            
    getDomPosition (dom) {
                if (dom) {
                    return Array.from(dom).map(node => {
                        let style = null
                        if (window.getComputedStyle) {
                            style = window.getComputedStyle(node, null) // 非IE
                        } else {
                            style = node.currentStyle // IE
                        }
                        const { top: t, left: l } =
                            node.getBoundingClientRect() || {}
                        // const top = parseInt(node.offsetTop, 10);     //相对于父元素
                        // const left = parseInt(node.offsetLeft, 10);   //相对于父元素
                        const top = parseInt(t, 10) // 相对于窗口
                        const left = parseInt(l, 10) // 相对于窗口
                        const width = parseInt(style.width, 10)
                        const height = parseInt(style.height, 10)
                        return { left, top, width, height }
                    })
                } else {
                    return []
                }
            },
  • 相关阅读:
    换零钞
    空心菱形
    生成回文数
    机器人数目
    胡同门牌号
    七星填数
    阶乘位数
    打印数字
    平方末尾
    数位和
  • 原文地址:https://www.cnblogs.com/lh1998/p/13692491.html
Copyright © 2011-2022 走看看