乐趣区

关于javascript:js-判断元素是否在可视区域

 isElementInViewport(el) {
      // 获取元素是否在可视区域
      var rect = el.getBoundingClientRect();
      return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <=
          (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <=
          (window.innerWidth || document.documentElement.clientWidth)
      );
    },
// 应用
 const keyDiv = document.getElementById("xxxld");
 this.isElementInViewport(keyDiv)
退出移动版