Vue组件之区域滚动

区域滚动组件

功能css

滚动到底部加载新内容

js代码app

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代码code

.above {
        position: fixed;
        z-index: 1;
        width: 200px;
        height: 200px;
        background: #f0f;
        top: 50%;
        left: 50%;
        margin: auto;
}
相关文章
相关标签/搜索