Detect if an element is visible (without using jQuery)

前端 未结 5 803
执笔经年
执笔经年 2021-02-07 11:20

I\'m trying to detect if an html element I gave an id is visible or not without using jquery.

The context:

In the forgotten user password page,

5条回答
  •  温柔的废话
    2021-02-07 11:46

    Google helped me finding out how jQuery does it, you can do the same:

    In jQuery 1.3.2 an element is visible if its browser-reported offsetWidth or offsetHeight is greater than 0.

    Release notes

    Searching the source code gave me this:

    // The way jQuery detect hidden elements, and the isVisible just adds "!".
    elem.offsetWidth === 0 && elem.offsetHeight === 0
    

提交回复
热议问题