Skip to content

Commit 3402ecc

Browse files
committed
添加 scrollTo 兼容方法
1 parent 97deae9 commit 3402ecc

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

packages/src/utils/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,22 @@ export function getChildCompsByName(context, name) {
126126
return result;
127127
}
128128

129+
/*
130+
* @scrollTo
131+
* @desc element scrollTo https://developer.mozilla.org/zh-CN/docs/Web/API/Element/scrollTo
132+
* @param {element} el - element
133+
* @param {object} option - scroll option
134+
*/
135+
export function scrollTo(el, option) {
136+
if (isFunction(el.scrollTo)) {
137+
el.scrollTo(option);
138+
} else {
139+
const { top, left } = option;
140+
el.scrollTop = top;
141+
el.scrollLeft = left;
142+
}
143+
}
144+
129145
/*获取当前元素的left、top偏移
130146
* left:元素最左侧距离文档左侧的距离
131147
* top:元素最顶端距离文档顶端的距离

0 commit comments

Comments
 (0)