Vue组件之区域滚动

区域滚动组件

功能

    滚动到底部加载新内容

js代码

let bool = false
Vue.directive('scrollDown', {
  bind (el, binding, vNode, oldNode) {
    el.addEventListener('scroll', () => {
      if (el.scrollTop + el.clientHeight === el .scrollHeight) {
        if (!bool) {
          var tip = document.createElement('div')
          tip.className="above"
          tip.innerHTML = '正在请求'
          el.appendChild(tip)
          setTimeout(() => {
            console.log('data')
            bool = false
            el.removeChild(tip)
          }, 1500)
        }
      }
    })
  }
})

css代码

.above {
        position: fixed;
        z-index: 1;
        width: 200px;
        height: 200px;
        background: #f0f;
        top: 50%;
        left: 50%;
        margin: auto;
}
posted @ 2017-11-23 15:47  君寻不惑  阅读(803)  评论(0编辑  收藏  举报