Newer
Older
KaiFengPC / src / utils / resizeObserver.js
@zhangdeliang zhangdeliang on 23 May 405 bytes 初始化项目
import { debounce } from '@/utils'

export default function createResizeObserver(target, func) {
  let deFunc = null
  let first = true
  if(func) deFunc = debounce(() => {
    if(first) return (first = false)
    func()
  }, 100)
  const observer = new ResizeObserver((entries, observer) => {
    deFunc && deFunc()
  });
  observer.observe(target);
  return () => {
    observer.unobserve(target)
  }
}