1 Star 0 Fork 0

Maybe / v-touchshow

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

v-touchshow

基于any-touch手势库封装的Vue(2 & 3)的指令

如果觉得还不错, star一下项目, 也可以在网页底部捐赠给作者一杯咖啡钱,Thanks♪(・ω・)ノ。

npm version downloads Jsdelivr Hits star star

安装

Vue3

yarn add @maybecode/v-touchshow

Vue2

yarn add @maybecode/v-touchshow @vue/composition-api

注册

Vue3

import { createApp } from 'vue';
import VTouchshow from '@maybecode/v-touchshow'

const app = createApp();

app.use(VTouchshow);

Vue2

import Vue from 'vue';
import VTouchshow from '@maybecode/v-touchshow'

Vue.use(VTouchshow);

在线演示

Demo

具体使用

手势识别器支持事件对照表

识别器 事件名 说明
tap tap 单击
press press / pressup 按压 / 松开
pan pan / panstart / panmove / panend /panup/pandown/panright/panleft 拖拽 / 拖拽开始 / 拖拽进行中 / 拖拽结束/ 上下左右滑动
swipe swipe / swipeup / swipedown / swiperight / swipeleft 快划 / 不同方向快划
pinch pinch / pinchstart / pinchmove / pinchend / pinchin /pinchout 缩放 / 缩放开始 / 缩放进行中 / 缩放结束 / 放大 / 缩小
rotate rotate / rotatestart / rotatemove / rotateend 旋转 / 旋转开始 / 旋转进行中 / 旋转结束

可传入配置兼容any-touch

<div
    v-touchshow="config"
 >
</div>

1. 设置过渡动画

<style>

.block{
    transition: transform 0.3s ease-in-out; // 设置过渡动画
}
</style>

2. 编写模板代码

<template>
<div
    class="block"
    v-touchshow:swipeup="onSwipeup"
>
</div>
</template>

3. 处理事件回调

<script lang="ts" setup>
import { Callback } from '@maybecode/v-touchshow';

const onSwipeup: Callback = (e, el) => {
    el.style.transform = "translateY(-30vw)"
}
</script>

移动端尽量使用 tap 代理 click

在移动端 touchstart 比 click 先触发, 所以 touchstart 阶段的 preventDefault 会阻止 click 触发, 恰恰 any-touch 默认在 touchstart 中使用了preventDefault, 用来阻止了浏览器默认事件的触发,比如 click 和页面滚动.

如果移动端非要使用 click 做如下设置

v-touchshow="{ preventDefault: false }"

Browsers support

IE / EdgeEdge FirefoxFirefox ChromeChrome SafariSafari
Edge last 2 versions last 2 versions last 2 versions

赞助

优先处理问题,以及定制化方案

License

MIT

MIT License Copyright (c) 2022 Maybe Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于any-touch手势库封装的Vue(2 & 3)的指令 展开 收起
TypeScript 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
TypeScript
1
https://gitee.com/null_639_5368/v-touchshow.git
git@gitee.com:null_639_5368/v-touchshow.git
null_639_5368
v-touchshow
v-touchshow
master

搜索帮助