提交 bc78cc6d 编写于 作者: D DCloud_LXH

fix(h5): pageScrollTo selector

上级 414101ca
......@@ -10,7 +10,7 @@ import { scrollTo } from '@dcloudio/uni-shared'
export const pageScrollTo = defineAsyncApi<API_TYPE_PAGE_SCROLL_TO>(
API_PAGE_SCROLL_TO,
({ scrollTop, selector, duration }, { resolve }) => {
scrollTo(selector! || scrollTop! || 0, duration!)
scrollTo(selector! || scrollTop! || 0, duration!, true)
resolve()
},
PageScrollToProtocol,
......
......@@ -504,11 +504,15 @@ function addFont(family, source, desc) {
resolve();
});
}
function scrollTo(scrollTop, duration) {
function scrollTo(scrollTop, duration, isH5) {
if (shared.isString(scrollTop)) {
const el = document.querySelector(scrollTop);
if (el) {
scrollTop = el.getBoundingClientRect().top + window.pageYOffset;
const { height, top } = el.getBoundingClientRect();
scrollTop = top + window.pageYOffset;
if (isH5) {
scrollTop -= height;
}
}
}
if (scrollTop < 0) {
......
......@@ -606,7 +606,7 @@ export declare const sanitise: (val: unknown) => any;
export declare const SCHEME_RE: RegExp;
declare function scrollTo_2(scrollTop: number | string, duration: number): void;
declare function scrollTo_2(scrollTop: number | string, duration: number, isH5?: boolean): void;
export { scrollTo_2 as scrollTo }
export declare const SELECTED_COLOR = "#0062cc";
......
......@@ -500,11 +500,15 @@ function addFont(family, source, desc) {
resolve();
});
}
function scrollTo(scrollTop, duration) {
function scrollTo(scrollTop, duration, isH5) {
if (isString(scrollTop)) {
const el = document.querySelector(scrollTop);
if (el) {
scrollTop = el.getBoundingClientRect().top + window.pageYOffset;
const { height, top } = el.getBoundingClientRect();
scrollTop = top + window.pageYOffset;
if (isH5) {
scrollTop -= height;
}
}
}
if (scrollTop < 0) {
......
......@@ -56,11 +56,19 @@ export function addFont(
})
}
export function scrollTo(scrollTop: number | string, duration: number) {
export function scrollTo(
scrollTop: number | string,
duration: number,
isH5?: boolean
) {
if (isString(scrollTop)) {
const el = document.querySelector(scrollTop)
if (el) {
scrollTop = el.getBoundingClientRect().top + window.pageYOffset
const { height, top } = el.getBoundingClientRect()
scrollTop = top + window.pageYOffset
if (isH5) {
scrollTop -= height
}
}
}
if (scrollTop < 0) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册