Newer
Older
KaiFengPC / src / utils / resizeObserver.js
@zhangdeliang zhangdeliang on 23 May 405 bytes 初始化项目
  1. import { debounce } from '@/utils'
  2.  
  3. export default function createResizeObserver(target, func) {
  4. let deFunc = null
  5. let first = true
  6. if(func) deFunc = debounce(() => {
  7. if(first) return (first = false)
  8. func()
  9. }, 100)
  10. const observer = new ResizeObserver((entries, observer) => {
  11. deFunc && deFunc()
  12. });
  13. observer.observe(target);
  14. return () => {
  15. observer.unobserve(target)
  16. }
  17. }