/**
 * 粘性 类似 position:sticky;
 */
function install(Vue: any, _ = {}) {
  Vue.directive('sticky', {
    inserted(el: any, _1: any, _2: any) {
      let change = false
      const dom = document.querySelector(
        '.avue-content>.el-scrollbar>.el-scrollbar__wrap',
      )
      if (dom) {
        dom.addEventListener('scroll', (_: any) => {
          if (change === false) {
            el.parentNode.style.paddingTop = `${el.offsetHeight}px`
            el.classList.add('lenx-sticky')
            change = true
          }
          // if (e.target.scrollTop == 0) {
          //     el.classList.remove('lenx-sticky');
          // } else {
          //     el.classList.add('lenx-sticky');
          // }
        })
      }
    },
  })
}

export default { install }
