mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Field: optimize root scroll top (#3222)
This commit is contained in:
parent
821639c47e
commit
23792ce16f
@ -1,7 +1,8 @@
|
|||||||
import { use, isObj, isDef, isIOS } from '../utils';
|
|
||||||
import Icon from '../icon';
|
import Icon from '../icon';
|
||||||
import Cell from '../cell';
|
import Cell from '../cell';
|
||||||
import { cellProps } from '../cell/shared';
|
import { cellProps } from '../cell/shared';
|
||||||
|
import { use, isObj, isDef, isIOS } from '../utils';
|
||||||
|
import { getRootScrollTop } from '../utils/scroll';
|
||||||
|
|
||||||
const [sfc, bem] = use('field');
|
const [sfc, bem] = use('field');
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ export default sfc({
|
|||||||
// https://developers.weixin.qq.com/community/develop/doc/00044ae90742f8c82fb78fcae56800
|
// https://developers.weixin.qq.com/community/develop/doc/00044ae90742f8c82fb78fcae56800
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
if (isIOS()) {
|
if (isIOS()) {
|
||||||
window.scrollTo(0, window.pageYOffset);
|
window.scrollTo(0, getRootScrollTop());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -29,6 +29,10 @@ export function setScrollTop(element: ScrollElement, value: number) {
|
|||||||
'scrollTop' in element ? (element.scrollTop = value) : element.scrollTo(element.scrollX, value);
|
'scrollTop' in element ? (element.scrollTop = value) : element.scrollTo(element.scrollX, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getRootScrollTop(): number {
|
||||||
|
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
|
||||||
|
}
|
||||||
|
|
||||||
// get distance from element top to page top
|
// get distance from element top to page top
|
||||||
export function getElementTop(element: ScrollElement) {
|
export function getElementTop(element: ScrollElement) {
|
||||||
return (
|
return (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user