* Scrolls the page to the given element. * @param {?Element} elem * @param {string} hash * @private
(elem, hash)
| 653 | * @private |
| 654 | */ |
| 655 | scrollToElement_(elem, hash) { |
| 656 | // Scroll to the element if found. |
| 657 | if (elem) { |
| 658 | // The first call to scrollIntoView overrides browsers' default scrolling |
| 659 | // behavior. The second call insides setTimeout allows us to scroll to |
| 660 | // that element properly. Without doing this, the viewport will not catch |
| 661 | // the updated scroll position on iOS Safari and hence calculate the wrong |
| 662 | // scrollTop for the scrollbar jumping the user back to the top for |
| 663 | // failing to calculate the new jumped offset. Without the first call |
| 664 | // there will be a visual jump due to browser scroll. See |
| 665 | // https://github.com/ampproject/amphtml/issues/5334 for more details. |
| 666 | this.viewport_./*OK*/ scrollIntoView(elem); |
| 667 | Services.timerFor(this.ampdoc.win).delay( |
| 668 | () => this.viewport_./*OK*/ scrollIntoView(dev().assertElement(elem)), |
| 669 | 1 |
| 670 | ); |
| 671 | } else { |
| 672 | dev().warn( |
| 673 | TAG, |
| 674 | `failed to find element with id=${hash} or a[name=${hash}]` |
| 675 | ); |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | /** |
| 680 | * @param {string} url |
no test coverage detected