Javascript Tool: Detect if a DOM Element is Truly Visible
来源:互联网 发布:淘宝 评价数 销量 编辑:程序博客网 时间:2024/05/20 12:50
one way:
According to this MDN documentation, an element's offsetParent property will return null whenever it, or any of its parents, is hidden via the display style property. Just make sure that the element isn't fixed. A script to check this, if you have no 'position:fixed;' elements on your page, might look like:
//Where el is the DOM element you'd like to test for visibilityfunction isHidden(el) { if (el.offsetParent === null) { return true; } return false;}
On the other hand, if you do have position fixed elements that might get caught in this search, you will sadly (and slowly) have to use window.getComputedStyle(). The function in that case might be:
//Where el is the DOM element you'd like to test for visibilityfunction isHidden(el) { var style = window.getComputedStyle(el); if (style.display === 'none') { return true; } return false;}
Option #2 is probably a little more straightforward since it accounts for more edge cases, but I bet its a good deal slower, too, so if you have to repeat this operation many times, best to probably avoid it.
another way:点击打开链接
- Javascript Tool: Detect if a DOM Element is Truly Visible
- detect if a URL is reachable
- How a DOM Element is Attached
- selenium:Element is not visible
- [React Error]: Target container is not a DOM element
- Webdriver Element is not currently visible 解决方法
- jquery中的is和is(":hidden") 或者 element.is(":visible")
- selenium +Python 测试时报 “Element is not visible”解决方法
- WebDriver遇到Element is not currently visible and so ...解决
- PRJ:Detect a point if it's inside a triangle
- fetch a dom element style
- JavaScript DOM(三) Element 类型
- 【JavaScript学习】DOM:Element类型
- error : A file found in a source-path must have an externally visible definition. If a definition in the file is meant to be ext
- 【1】Detect if a string has all unique characters
- "This is truly an honor"中的truly是句子副词
- If God is a Programmer
- If a string is Palindromic
- java concurrent
- C++ Builder SelectDirectory 中文目录过长无法选择的问题
- Fragment+FragmentTabHost实现底部菜单栏
- repo的用法(zz)
- 《c++程序设计--谭浩强》读书笔记
- Javascript Tool: Detect if a DOM Element is Truly Visible
- VisionMobile:iOS8–Apple隐藏的议程
- ORA-15041: diskgroup space exhausted
- Lua面向对象
- 如何在sublime3中直接运行python
- 黑马程序员_GUI图形用户界面
- Intellij idea常用快捷键
- setup factor 打包界面 按钮操作
- 使用Tcl脚本分配FPGA管脚