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.
检查元素的顶部和左侧是否小于或等于当前滚动或视口位置,以及元素的高度和宽度是否等于或大于然后视口
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.
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.