extensions/amp-position-observer/0.1/amp-position-observer.js
/**
   * Calculates whether the scene is visible considering ratios and margins.
   * @param {!../../../src/layout-rect.LayoutRectDef} positionRect position rect as returned by position observer
   * @param {!../../../src/layout-rect.LayoutRectDef} adjustedViewportRect viewport rect adjusted for margins.
   * @param {!RelativePositions} relativePos Relative position of rect to viewportRect
   * @private
   */
Calculates whether the scene is visible considering ratios and margins.
Calculates whether the scene is visible considering ratios and margins .
updateVisibility_(positionRect, adjustedViewportRect, relativePos) {
    if (relativePos == RelativePositions.INSIDE) {
      this.isVisible_ = true;
      return;
    }
    const ratioToUse = relativePos == RelativePositions.TOP ?
        this.topRatio_ : this.bottomRatio_;
    const offset = positionRect.height * ratioToUse;
    if (relativePos == RelativePositions.BOTTOM) {
      this.isVisible_ =
        positionRect.top <= (adjustedViewportRect.bottom - offset);
    } else {
      this.isVisible_ =
        positionRect.bottom >= (adjustedViewportRect.top + offset);
    }
  }
updateVisibility_ ( positionRect , adjustedViewportRect , relativePos ) { if ( relativePos == RelativePositions . INSIDE ) { this . isVisible_ = true ; return ; } const ratioToUse = relativePos == RelativePositions . TOP ? this . topRatio_ : this . bottomRatio_ ; const offset = positionRect . height * ratioToUse ; if ( relativePos == RelativePositions . BOTTOM ) { this . isVisible_ = positionRect . top <= ( adjustedViewportRect . bottom - offset ) ; } else { this . isVisible_ = positionRect . bottom >= ( adjustedViewportRect . top + offset ) ; } }
Calculates whether the scene is visible considering ratios and margins.
Calculates whether the scene is visible considering ratios and margins .
// Fully inside margin-adjusted viewport.