1.0.3 • Published 2 years ago

@dsh-prose/event v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

移动端自定义事件

import Event from '@dsh-prose/event';

const event = new Event(HTMLElement, {
  onLongPressUp() {
    console.log("onLongPressUp");
  },
  onLongPress() {
    console.log("onLongPress");
  },
  onSwipeLeft(distance) {
    console.log("onSwipeLeft");
  },
  onSwipeRight(distance) {
    console.log("onSwipeRight");
  },
  onSwipeUp(distance) {
    console.log("onSwipeUp");
  },
  onSwipeDown(distance) {
    console.log("onSwipeDown");
  },
  onSwipeVertical({type, distance, origin}) {
    console.log("onSwipeVertical", type, distance, origin);
  },
  onSwipeHorizontal({type, distance, origin}) {
    console.log("onSwipeHorizontal", type, distance, origin);
  }, 
  onSwipeRound: ({ type, current, origin }) => {
    console.log("onSwipeRound", type, current, origin);
  },
  onScale(scale) {
    console.log("onScale");
  },
});

Event 事件参数

onLongPressUp (长按抬起)

(回调值: ) | 参数 | 说明 | 默认值 | 类型 | 必选 | |---------|-------------------------|--------|--------|:----:| | minTime | 触发最小时间 包含此值 | 700 | number | × | | maxTime | 触发最大时间 包含此值 | Infinity | number | × | | minMove | 触发最小移动距离 包含此值 | 0 | number | × | | maxMove | 触发最大移动距离 包含此值 | 4 | number | × | | preventDefault | (start)时阻止默认事件 | true | boolean | × |

onLongPress (长按)

(回调值: ) | 参数 | 说明 | 默认值 | 类型 | 必选 | |---------|-------------------------|--------|--------|:----:| | minTime | 触发最小时间 包含此值 | 700 | number | × | | minMove | 触发最小移动距离 包含此值 | 0 | number | × | | maxMove | 触发最大移动距离 包含此值 | 4 | number | × | | preventDefault | (start)时阻止默认事件 | true | boolean | × |

onSwipeLeft (左向滑动) | onSwipeRight (右向滑动) | onSwipeUp (上向滑动) | onSwipeDown (下向滑动)

(回调值: distance移动距离。 单位: px) | 参数 | 说明 | 默认值 | 类型 | 必选 | |---------|-------------------------|--------|--------|:----:| | minMove | 触发最小移动距离 包含此值 | 10 | number | × | | allowBack | 在触发滑动事件后,再往回划 distance 是否能得到负值 | false | boolean | × | | minAngle | 最小大于此角度 不包含此值 | (Left-Right-Up-Down) (135-315-225-45) | number | × | | maxAngle | 最大小于此角度 不包含此值 | (Left-Right-Up-Down) (225-45-315-135) | number | × | | preventDefault | (start)时阻止默认事件,垂直滚动时适用(Up Down) | (Up Down-Left Right) (true-false) | boolean | × | | triggerPreventDefault | (move 达到触发条件)时阻止默认事件,垂直滚动时适用(Left Right) | (Up Down-Left Right) (false-true) | boolean | × |

onSwipeVertical (竖向滑动) | onSwipeHorizontal (横向滑动)

(回调值: type触发类型, distance移动距离。 单位: px, origin触发事件的坐标) | 参数 | 说明 | 默认值 | 类型 | 必选 | |---------|-------------------------|--------|--------|:----:| | angles | 触发角度| vertical: { min: 225, max: 315 }, { min: 45, max: 135 } horizontal: { min: 135, max: 225 }, { min: 315, max: 45 } | Array<{ min: number; max: number }> | × | | preventDefault | (start)时阻止默认事件,垂直滚动时适用(vertical) | (vertical-horizontal) (true-false) | boolean | × | | triggerPreventDefault | (move 达到触发条件)时阻止默认事件,垂直滚动时适用(horizontal) | (vertical-horizontal) (false-true) | boolean | × |

onSwipeRound (滑动)

(回调值: type触发类型, current当前的坐标, origin触发事件的坐标) | 参数 | 说明 | 默认值 | 类型 | 必选 | |---------|-------------------------|--------|--------|:----:| | preventDefault | start 时阻止默认事件 | true | boolean | × |

onScale (双指缩放)

(回调值: scale缩放距离。 单位: px) | 参数 | 说明 | 默认值 | 类型 | 必选 | |---------|-------------------------|--------|--------|:----:| | preventDefault | start 时阻止默认事件 | true | boolean | × |

Event 解绑事件

event.destroy()
1.0.2

2 years ago

1.0.3

2 years ago

0.1.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.2-alpha.3

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

3 years ago

0.0.3

3 years ago