js 获取元素宽高的几种方法

1、Element.style.width/height

只能获取内联样式

2、window.getComputedStyle(ele).width/height

可获取实时的 style

3、Element.currentStyle.width/height

功能与第二点相同,只存在于旧版本 IE 中(IE9 以下),除了做旧版 IE 兼容,就不要用它了。

4、Element.getBoundingClientRect().width/height

除了能够获取宽高,还能获取元素位置等信息

相关推荐

  1. js 获取元素方法

    2023-12-16 01:28:03       53 阅读
  2. android 在onCreate方法获得view

    2023-12-16 01:28:03       31 阅读
  3. next.js 渲染方式

    2023-12-16 01:28:03       31 阅读
  4. js 移动数组元素方法

    2023-12-16 01:28:03       21 阅读
  5. CSS设置元素

    2023-12-16 01:28:03       40 阅读
  6. 【TORCH】获取第一个batch数值方法

    2023-12-16 01:28:03       25 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-16 01:28:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-16 01:28:03       101 阅读
  3. 在Django里面运行非项目文件

    2023-12-16 01:28:03       82 阅读
  4. Python语言-面向对象

    2023-12-16 01:28:03       91 阅读

热门阅读

  1. Future设计模式

    2023-12-16 01:28:03       50 阅读
  2. 包管理工具npm与yarn

    2023-12-16 01:28:03       53 阅读
  3. 除法求值[中等]

    2023-12-16 01:28:03       44 阅读
  4. 爬取图片python代码

    2023-12-16 01:28:03       60 阅读
  5. AI:ElasticSearch

    2023-12-16 01:28:03       60 阅读
  6. 4.2 进阶题 - B 相生相克

    2023-12-16 01:28:03       59 阅读
  7. linux/CentOS7安装mysql数据库

    2023-12-16 01:28:03       68 阅读