mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-29 00:10:54 +05:30
Fix scrollTo function: targetEl is now has priority on location hash
This commit is contained in:
parent
cb00d0c712
commit
fe9de056df
@ -106,24 +106,27 @@ function normalizeScrollPosition(y: number): number {
|
|||||||
* @param {?HTMLElement} targetEl - the element to scroll to
|
* @param {?HTMLElement} targetEl - the element to scroll to
|
||||||
*/
|
*/
|
||||||
export function restoreScroll(targetEl: ?HTMLElement = null) {
|
export function restoreScroll(targetEl: ?HTMLElement = null) {
|
||||||
const {hash} = location;
|
const { hash } = window.location;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
isFirstScroll = false;
|
isFirstScroll = false;
|
||||||
const id = hash.replace('#', '');
|
if (targetEl === null) {
|
||||||
const el = id ? document.getElementById(id) : targetEl;
|
const id = hash.substr(1);
|
||||||
const viewPort = document.body;
|
if (!id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
targetEl = document.getElementById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const viewPort = document.body;
|
||||||
if (!viewPort) {
|
if (!viewPort) {
|
||||||
console.log('Can not find viewPort element'); // eslint-disable-line
|
console.log('Can not find viewPort element'); // eslint-disable-line
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let y = 0;
|
let y = 0;
|
||||||
|
if (targetEl) {
|
||||||
if (el) {
|
const { top } = targetEl.getBoundingClientRect();
|
||||||
const {top} = el.getBoundingClientRect();
|
|
||||||
|
|
||||||
y = getScrollTop() + top - SCROLL_ANCHOR_OFFSET;
|
y = getScrollTop() + top - SCROLL_ANCHOR_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user