GithubHelp home page GithubHelp logo

alloyteam / alloyfinger Goto Github PK

View Code? Open in Web Editor NEW
3.4K 133.0 541.0 1.15 MB

Super tiny size multi-touch gestures library for the web.    You can touch this →

Home Page: http://alloyteam.github.io/AlloyFinger/

License: MIT License

JavaScript 85.41% HTML 14.59%
touch gesture alloyfinger finger

alloyfinger's Introduction

Preview

You can touch this → http://alloyteam.github.io/AlloyFinger/

Install

You can install it via npm:

npm install alloyfinger

Usage

var af = new AlloyFinger(element, {
    touchStart: function () { },
    touchMove: function () { },
    touchEnd:  function () { },
    touchCancel: function () { },
    multipointStart: function () { },
    multipointEnd: function () { },
    tap: function () { },
    doubleTap: function () { },
    longTap: function () { },
    singleTap: function () { },
    rotate: function (evt) {
        console.log(evt.angle);
    },
    pinch: function (evt) {
        console.log(evt.zoom);
    },
    pressMove: function (evt) {
        console.log(evt.deltaX);
        console.log(evt.deltaY);
    },
    swipe: function (evt) {
        console.log("swipe" + evt.direction);
    }
});

/**
 * this method can also add or remove the event handler
 */
var onTap = function() {};

af.on('tap', onTap);
af.on('touchStart', function() {});

af.off('tap', onTap);

/**
 * this method can destroy the instance
 */
af = af.destroy();

Omi Version:

import { render, tag, WeElement } from 'omi'
import 'omi-finger'

@tag('my-app')
class MyApp extends WeElement {
  install() {
    this.data.wording = 'Tap or Swipe Me!'
  }

  handleTap = (evt) => {
    this.data.wording += '\r\nTap'
    this.update()
  }

  handleSwipe = (evt) => {
    this.data.wording += '\r\nSwipe-' + evt.direction
    this.update()
  }

  render() {
    return (
      <div>
        <omi-finger onTap={this.handleTap} abc={{a:1}} onSwipe={this.handleSwipe}>
          <div class="touchArea" >
            {this.data.wording}
          </div>
        </omi-finger>
      </div>
    )
  }

  css() {
    return `.touchArea{
                  background-color: green;
                  width: 200px;
                  min-height: 200px;
                  text-align: center;
                  color:white;
                  height:auto;
                  white-space: pre-line;
              }`
  }
}

render(<my-app></my-app>, 'body')

Others

License

This content is released under the MIT License.

alloyfinger's People

Contributors

blet avatar caesor avatar dexteryy avatar loadingwyn avatar maiff avatar seognil avatar wbpmrck avatar wrxpowered avatar xcatliu avatar yongx avatar yuanfang-fe avatar yuqianma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

alloyfinger's Issues

魅族手机点不了

  <AlloyFinger onTap={this._handleClick}>
      <a className="good" href="javascript:;">
       ...
      </a>
    </AlloyFinger>

react 0.15下报错

Uncaught TypeError: Cannot read property 'bind' of undefined

var AlloyFinger = function (el, option) {

el.addEventListener("touchstart", this.start.bind(this), false);

el.addEventListener("touchmove", this.move.bind(this), false);

el.addEventListener("touchend", this.end.bind(this), false);

el.addEventListener("touchcancel",this.cancel.bind(this),false);

是这里的start报的

destroy need to check if not null

when you do something like:
this.rotate.del();
sometimes this.rotate can be null

I think it should check for existence before try to delete anything like:

           if (this.rotate) this.rotate.del();
           if (this.touchStart) this.touchStart.del();
           if (this.multipointStart) this.multipointStart.del();
           if (this.multipointEnd) this.multipointEnd.del();
           if (this.pinch) this.pinch.del();
           if (this.swipe) this.swipe.del();
           if (this.tap) this.tap.del();
           if (this.doubleTap) this.doubleTap.del();
           if (this.longTap) this.longTap.del();
           if (this.singleTap) this.singleTap.del();
           if (this.pressMove) this.pressMove.del();
           if (this.touchMove) this.touchMove.del();
           if (this.touchEnd) this.touchEnd.del();
           if (this.touchCancel) this.touchCancel.del();

屏幕滚动被禁止

在绑定手势的元素上无法触发屏幕滚动,touchmove中调用了preventDefault方法,这样对使用场景有很大限制

react里用报错 找不到'bind'

React版本下使用报错如下:
Uncaught TypeError: Cannot read property 'bind' of undefined at AlloyFinger (eval at <anonymous> (main.js:1305), <anonymous>:72:32) at eval (eval at <anonymous> (main.js:1070), <anonymous>:4760:16) at measureLifeCyclePerf (eval at <anonymous> (main.js:1070), <anonymous>:4529:12) at ReactCompositeComponentWrapper._constructComponentWithoutOwner (eval at <anonymous> (main.js:1070), <anonymous>:4759:14) at ReactCompositeComponentWrapper._constructComponent (eval at <anonymous> (main.js:1070), <anonymous>:4734:21) at ReactCompositeComponentWrapper.mountComponent (eval at <anonymous> (main.js:1070), <anonymous>:4642:21) at Object.mountComponent (eval at <anonymous> (main.js:1070), <anonymous>:11542:35) at ReactDOMComponent.mountChildren (eval at <anonymous> (main.js:1070), <anonymous>:10429:44) at ReactDOMComponent._createInitialChildren (eval at <anonymous> (main.js:1070), <anonymous>:6164:32) at ReactDOMComponent.mountComponent (eval at <anonymous> (main.js:1070), <anonymous>:5983:12)
请问是怎么回事

swipe的事件

你好,swipe只提供了direction方向,有什么办法设置触发swipe的阈值,或者也提供detailX,detailY等相关信息

Allow scrolling on gesture targets

Hi,

Fantastic library!

One small problem, though: because gesture targets prevent default touch behaviour, I am unable to scroll the page normally when my finger lands on the image.

Not sure how simple this is to fix, but thought I'd bring it up :)

tap和singleTap 有什么区别?

this.tapTimeout = setTimeout(function () {
    self.tap(evt);
    // trigger double tap immediately
    if (self.isDoubleTap) {
        self.doubleTap(evt);
        clearTimeout(self.touchTimeout);
        self.isDoubleTap = false;
    }else{
        self.touchTimeout=setTimeout(function(){
            self.singleTap(evt);
        },250);
    }
}, 0)

看了源码一个是马上触发,一个要250,有啥用?为什么不统一就用一种?

vue-cli引入AlloyFinger绑定事件方法中console.log(this)报错

npm安装AlloyFinger后

import AlloyFinger from 'alloyfinger';
import AlloyFingerVue from './libs/alloy_finger.vue';

Vue.use(AlloyFingerVue, { AlloyFinger });

绑定事件

    <div style="width: 100%; height: 40px; text-align: center;" v-finger:tap="tap">
      <span>↑</span>
    </div>

tap方法

    tap() {
      console.log(this);
    },

结果报错
[Vue warn]: Property or method "splice" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

alloy_finger.js写法疑问

作者您好,新手提问,阅读源码 alloy_finger.js 源码后我有两个疑问点,

  1. 源码第173行的 if (evt.touches.length > 1) 我感觉判断条件 evt.touches.length 就是之前的 len,这里没有 setTimeOut 跳出,为什么没有和前面的 if(len > 1) 合并呢?
  2. touchmove 中 this._cancelLongTap()一定会被执行的,设定跟 zepto-touch.js 类似,那么刚刚括号里面再次执行 this._cancelLongTap() 是不是就显得多余?

很有可能是我的理解有误,盼不吝赐教~~~~~~~~

附源码阅读笔记

AlloyCrop问题

在小米3/4/note上,使用微信最新版本,发现进行裁剪的时候,无法放大缩小,会卡死。

swipe 事件源码疑问

在查看 alloy_finger 源码的时候,对 swipe 事件的判断有些疑问。截图如下:
195 行
image

判断是否 swipe 事件, Y 轴方向用的是 Math.abs(this.preV.y - this.y2) > 30
其中 this.y2 是在 move 函数中设置的;
而只有 touches.length > 1 时,才会在 startmove 函数中设置 this.preV.y,否则 this.preV 的值是 { x: null, y: null }

是不是意味着,如果只是一根手指滑动,依次触发 touchstart touchmove touchend
那么 end 函数判断 swipe 的这句代码,由于 this.preV.y 值为 null 导致 Math.abs(this.preV.y - this.y2) > 30 报错呢?是不是应该改成 Math.abs(this.y1 - this.y2) > 30 呢?

pressMove事件有问题

元素拖不动不知道怎么回事,pressmove事件有响应,但是对应的位移只有0,1,2这样子

这些手势事件怎么阻止冒泡呢?

我使用了tap事件,想在回调里通过 evt.stopPropagation(); 来阻止事件冒泡,但是无效。

是因为源码里通过setTimeout来把同步变成异步,所以阻止冒泡失效了吗?

container??

Very good work, works very well the library, is it possible to restrict the pinch and pressMove gesture to a specific area ? like a container?

13行错别字

line 13: throw "can't set circle to ture when width is not equal to height"

第56行HandlerAdmin.prototype.dispatch的一点疑问

第56行for 循环,我个人觉得有必要加上 typeof this.handlers[i] === 'function' 的判断,原因如下:

  • 调用del传参为空的时候,会清空数组,本意是销毁实例的时候清空该方法的回调。但是如果用户在代码逻辑中逐个 del(handler)导致数组为空、或者是误使用了 del(),之后再 dispatch 对应的回调,会导致错误抛出。

  • 撇开使用场景,谁也不能保证 for 循环中得到的 item就一定是个函数。

如何对父子对象同时使用AlloyFinger--swipe

请教:
我对及里面的某个

同时应用swipe,并希望他们做出不同的响应。但现在在滚动子div时,总是同时响应了body的代码,我在div的代码中使用了evt.stopPropagation();也不行。请问如何处理?

new AlloyFinger(obj, {
    swipe: function(evt) {
        evt.stopPropagation();
        if (evt.direction == "Left") {
            $(obj).addClass("right");
        }

        if (evt.direction == "Right") {
            $(obj).removeClass("right");
        }
    }

});

求教longtap如何阻止浏览器默认事件

longTap(evt) {
      alert(11111111);
      evt.preventDefault();
      evt.stopPropagation();
    },
    tap() {
        this.$router.push('/worksDetail');
    }

尝试了上面的,但还是无效,此外这longtap和tap事件绑在同一个dom时,如何阻止longtap触发tap?

Vue里如何像原生的@click事件一样的传参数

vue2的传参问题

当我给事件绑定了

<div 
    v-finger:tap="tap('我是参数')"
</div>
methods: {
	tap: function(e) { console.log(e)}
 }

那么这样的这个tap事件当我一进入页面的时候就会被触发(在chrome模拟的移动端设备)。再点击的话,j就再也触发不了tap事件了。

currentTarget null

this.swipeTimeout = setTimeout(function () {
self.swipe(evt);
}, 0);

这里会导致currentTarget==null,感觉currentTarget对于时间代理绑定很有用啊,是不是考虑增加

请问怎么在vue-cli里面最方便的引入?

Vue.use(AlloyFingerVue)这种在main.js里面根本无法引入,

import AlloyFinger from './lib/alloy_finger'
import AlloyFingerVue from './lib/af'
//上面的就是那个为vue专门配置的js文件
Vue.use(AlloyFingerVue)

这是报错

Uncaught Error: you need include the AlloyFinger!
    at Object.install (eval at <anonymous> (app.js:1099), <anonymous>:15:15)
    at Function.Vue.use (eval at <anonymous> (app.js:1047), <anonymous>:3433:22)
    at eval (eval at <anonymous> (app.js:812), <anonymous>:23:45)
    at Object.<anonymous> (app.js:812)
    at __webpack_require__ (app.js:654)
    at fn (app.js:84)
    at Object.<anonymous> (app.js:1133)
    at __webpack_require__ (app.js:654)
    at app.js:701

ios拍摄的照片旋转问题

iphone从相册选择手机拍摄的照片或者直接照相,图片会有旋转的问题,需要用exif.js读取下图片的元数据,根据exifdata.Orientation来做旋转处理

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.