export default {
  bind: function (el, binding, vnode) {
    const docEl = document.documentElement
    const move = function (e) {
      e.preventDefault()
      if (e.targetTouches.length === 1) {
        const touch = e.targetTouches[0]
        _setPosition(touch)
      }
    }

    function _setPosition (touch) {
      if (touch.clientY <= 40) {
        el.style.top = '0px'
      } else if (touch.clientY > (docEl.clientHeight - el.clientHeight - 47)) {
        el.style.top = (docEl.clientHeight - el.clientHeight - 47) + 'px'
      } else {
        el.style.top = (touch.clientY - (el.clientHeight / 2)) + 'px'
      }
      if (touch.clientX <= 40) {
        el.style.left = '0px'
      } else if (touch.clientX > (docEl.clientWidth - el.clientWidth + 10)) {
        el.style.left = (docEl.clientWidth - el.clientWidth) + 'px'
      } else {
        el.style.left = (touch.clientX - (el.clientWidth / 2)) + 'px'
      }
    }

    const up = function (e) {
      const touch = e.changedTouches[0]

      _setPosition(touch)
      el.removeEventListener('touchmove', move)
      el.removeEventListener('touchend', up)
      binding.value && binding.value()
    }

    const down = function (e) {
      el.addEventListener('touchmove', move, false)
      el.addEventListener('touchend', up, false)
    }

    el.addEventListener('touchstart', down, false)
  }
}

  

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2021-09-22
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-30
  • 2022-03-05
  • 2021-11-03
  • 2021-09-01
  • 2022-12-23
相关资源
相似解决方案