0

I found this solution here: https://stackoverflow.com/a/7557433/5628

However, this is only for determining whether an element is visible within the viewport.

Instead: What I am attempting to do is slightly different in that I would like to determine whether the element takes up the entire viewport.

Community
  • 1
  • 1
u353
  • 990
  • 2
  • 9
  • 16

2 Answers2

0

check if element top and left are smaller or equal to current scroll or viewport position, and if element height and width is equal or larger then viewport

Noino
  • 593
  • 4
  • 13
0

You'll need to adjust the code a bit, but this works perfectly using a tiny bit of jQuery:

$(window).resize(function () {
    myFun.elementBiggerThanViewportCallback();
});

myFun.elementBiggerThanViewport = function (el) {

    //special bonus for those using jQuery
    if (el instanceof jQuery) {
        el = el[0];
    }

    var rect = el.getBoundingClientRect();

    return (
        rect.top <= 0 &&
        rect.bottom >= (window.innerHeight || document.documentElement.clientHeight)
    );
}

elementBiggerThanViewportCallback = function (el) {
    var ifBigger = tabccordion.elementBiggerThanViewport(el);
    // Do stuff here.
}
u353
  • 990
  • 2
  • 9
  • 16