1

It's clear to me how to check if an element is visible on the page, by using the functions explained on this question.

//Where el is the DOM element you'd like to test for visibility
function isHidden(el) {
    return (el.offsetParent === null)
}

Or

//Where el is the DOM element you'd like to test for visibility
function isHidden(el) {
    var style = window.getComputedStyle(el);
    return (style.display === 'none')
}

But to avoid pooling for the isHidden(el) function, I'd like to be notified when a given element is made visible in the DOM (with pure JS, no jQuery or other frameworks).

In theory mutation observers could be used, but I need a solution for IE10+ browsers.

Any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Gilberto Torrezan
  • 5,113
  • 4
  • 31
  • 50
  • I'm guessing you have some other javascript that toggles visibility of DOM elements? Is there a reason not to have that same toggleing function execute the code you want to run? – Adam Konieska Dec 02 '15 at 22:07
  • @AdamKonieska I have that scenario but not only that. I have a case where the visibility is toggled on a CSS animation, and one where the visibility is toggled by a CSS media query. I'm seeking a single way to be notified when an element is made visible, to cover all the cases when this could happen, not only by toggling via javascript. – Gilberto Torrezan Dec 03 '15 at 03:41

0 Answers0