MCPcopy Index your code
hub / github.com/ampproject/amphtml / mutateElement_

Method mutateElement_

src/service/fixed-layer.js:785–830  ·  view source on GitHub ↗

* Mutates the fixed/sticky element. At this point it's determined that the * element is indeed fixed/sticky. There are two main functions here: * 1. `top` has to be updated to reflect viewer's paddingTop. * 2. The element may need to be transferred to the separate fixed layer. * * @

(fe, index, state)

Source from the content-addressed store, hash-verified

783 * @private
784 */
785 mutateElement_(fe, index, state) {
786 const {element, fixedNow: oldFixed} = fe;
787
788 fe.fixedNow = state.fixed;
789 fe.stickyNow = state.sticky;
790 fe.top = state.fixed || state.sticky ? state.top : '';
791 fe.transform = state.transform;
792
793 // Move back to the BODY layer and reset transfer z-index.
794 if (
795 oldFixed &&
796 (!state.fixed || !state.transferrable) &&
797 this.transferLayer_
798 ) {
799 this.transferLayer_.returnFrom(fe);
800 }
801
802 // Update `top` to adjust position to the viewer's paddingTop. However,
803 // ignore lightboxed elements since lightboxes ignore the viewer header.
804 if (state.top && (state.fixed || state.sticky) && !fe.lightboxed) {
805 if (state.fixed || !this.transfer_) {
806 // Fixed positions always need top offsetting, as well as stickies on
807 // non iOS Safari.
808 setStyle(element, 'top', `calc(${state.top} + ${this.paddingTop_}px)`);
809 } else {
810 // On iOS Safari (this.transfer_ = true), stickies cannot
811 // have an offset because they are already offset by the padding-top.
812 if (this.committedPaddingTop_ === this.paddingTop_) {
813 // So, when the header is shown, just use top.
814 setStyle(element, 'top', state.top);
815 } else {
816 // When the header is not shown, we need to subtract the padding top.
817 setStyle(
818 element,
819 'top',
820 `calc(${state.top} - ${this.committedPaddingTop_}px)`
821 );
822 }
823 }
824 }
825
826 // Move element to the fixed layer.
827 if (this.transfer_ && state.fixed && state.transferrable) {
828 this.getTransferLayer_().transferTo(fe, index, state);
829 }
830 }
831
832 /**
833 * @return {?TransferLayerDef}

Callers 11

updateMethod · 0.95
startSwipeMethod · 0.80
snapBackFromSwipe_Method · 0.80
swipeMoveMethod · 0.80
snapBackFromSwipe_Method · 0.80
dismissFromSwipe_Method · 0.80
swipeMove_Method · 0.80
snapBackFromSwipe_Method · 0.80
dismissFromSwipe_Method · 0.80
swipeMove_Method · 0.80

Calls 4

getTransferLayer_Method · 0.95
setStyleFunction · 0.90
returnFromMethod · 0.45
transferToMethod · 0.45

Tested by

no test coverage detected