/**
 * 获取当前滚动条所在位置
 */ export function getScrollTop ( ) { let scrollTop = 0 ; if ( document && document . documentElement && document . documentElement . scrollTop ) { scrollTop = document . documentElement . scrollTop ; } else if ( document . body ) { scrollTop = document . body . scrollTop ; } return scrollTop ; } param { * } position param { * } step param { * } current export function scrollToAnimate ( position = 0 , step = 100 , current = 0 ) { let start = 0 ; const timer = setInterval ( ( ) => { if ( current - start >= position ) { start += step ; if ( current - start >= position ) { window . scrollTo ( 0 , current - start ) ; } else { window . scrollTo ( 0 , position ) ; } } else { clearInterval ( timer ) ; } } , 0 ) ; } /**
 * 获取滚动条位置百分比
 */ export function getScrollPercent ( offsetTop = 0 ) { let percent = 0 ; if ( offsetTop < getScrollTop ( ) ) { percent = Math . round ( ( ( getScrollTop ( ) - offsetTop ) / ( document . body . scrollHeight - offsetTop - window . innerHeight ) ) * 100 ) ; } return percent > 100 ? 100 : percent ; }