UNPKG

xxm-test-js

Version:
28 lines (27 loc) 839 B
/** * 检测页面滚动方向。 * @returns {() => 'up' | 'down' | 'top' | 'bottom'} 返回一个函数,每次调用时返回当前的滚动方向。 * @example * ```typescript * // 使用示例 * // 在 Vue 2 组件中使用12-1 * export default { * data() { * return { * scrollDirection: '' as 'up' | 'down' | 'top' | 'bottom' * }; * }, * mounted() { * const getScrollDirection = detectScrollDirection(); * window.addEventListener('scroll', () => { * this.scrollDirection = getScrollDirection(); * console.log('当前滚动方向:', this.scrollDirection); * }); * }, * beforeDestroy() { * window.removeEventListener('scroll', this.handleScroll); * } * }; * ``` */ export declare function detectScrollDirection(): () => 'up' | 'down' | 'top' | 'bottom';