[improvement] Field: optimize root scroll top (#3222)

This commit is contained in:
neverland 2019-04-26 15:35:45 +08:00 committed by GitHub
parent 821639c47e
commit 23792ce16f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -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());
} }
}, },

View File

@ -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 (