Is there any way that I can check if an element is visible in pure JS (no jQuery) ?
(有什么方法可以检查元素在纯JS(无jQuery)中是否可见?)
So, for example, in this page: Performance Bikes , if you hover over Deals (on the top menu), a window of deals appear, but at the beginning it was not shown.
(因此,例如,在此页面: Performance Bikes中 ,如果将鼠标悬停在Deals上(在顶部菜单上),则会显示一个交易窗口,但一开始并未显示。)
It is in the HTML but it is not visible.(它在HTML中,但不可见。)
So, given a DOM element, how can I check if it is visible or not?
(那么,给定一个DOM元素,如何检查它是否可见?)
I tried:(我试过了:)
window.getComputedStyle(my_element)['display']);
but it doesn't seem to be working.
(但它似乎不起作用。)
I wonder which attributes should I check.(我想知道应该检查哪些属性。)
It comes to my mind:(我想到:)
display !== 'none'
visibility !== 'hidden'
Any others that I might be missing?
(还有其他我可能会想念的东西吗?)
ask by Hommer Smith translate from so