-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackTop.tsx
More file actions
37 lines (34 loc) · 764 Bytes
/
BackTop.tsx
File metadata and controls
37 lines (34 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { ArrowUpOutlined } from '@ant-design/icons';
import FloatButton from '.';
type BackTopProps = {
target?: HTMLElement | (() => HTMLElement);
};
const BackTop = ({ target }: BackTopProps) => {
return (
<FloatButton
icon={<ArrowUpOutlined />}
tooltip="返回顶部"
onClick={() => {
if (!target) {
window.scrollTo({
top: 0,
behavior: 'smooth',
});
return;
}
if (typeof target === 'function') {
target().scrollTo({
top: 0,
behavior: 'smooth',
});
return;
}
target.scrollTo({
top: 0,
behavior: 'smooth',
});
}}
/>
);
};
export default BackTop;