useMoveMenu.ts 775 B

1234567891011121314151617181920212223242526
  1. import {ref} from "vue";
  2. const listTouchStart = ref(0);
  3. const listTouchDirection = ref<string | null>('');
  4. const modalName = ref<string | null>('');
  5. // ListTouch触摸开始
  6. const handleListTouchStart = (e: any) => {
  7. listTouchStart.value = e.touches[0].pageX
  8. }
  9. // ListTouch计算方向
  10. const handleListTouchMove = (e: any) => {
  11. listTouchDirection.value = e.touches[0].pageX - listTouchStart.value > -80 ? 'right' : 'left'
  12. }
  13. // ListTouch计算滚动
  14. const handleListTouchEnd = (e: any) => {
  15. if (listTouchDirection.value == 'left') {
  16. modalName.value = e.currentTarget.dataset.target
  17. } else {
  18. modalName.value = null
  19. }
  20. listTouchDirection.value = null
  21. }
  22. export {modalName, handleListTouchStart, handleListTouchMove, handleListTouchEnd}