import React, { HTMLAttributes, useRef } from 'react';
import './index.scss';
export interface BackTopProps extends HTMLAttributes {
children?: React.ReactNode;
action: React.ReactNode;
}
const BackTop: React.FC = (props) => {
const { children, action } = props;
const wrapRef = useRef(null);
const scrollHeight = useRef(0);
const goTop = () => {
scrollHeight.current = wrapRef.current!.scrollTop;
const step = scrollHeight.current / 10;
const time = setInterval(() => {
if (scrollHeight.current > 0) {
wrapRef.current!.scrollTo(0, scrollHeight.current - step);
scrollHeight.current -= step;
} else {
window.clearInterval(time);
}
}, 5);
};
return (
);
};
BackTop.defaultProps = {
children: ''
};
export default BackTop;