forked from dotmaster/Touchable-jQuery-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (56 loc) · 4.17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<h1>NEW!!! NOW WORKING EVEN ON IE 7/8</h1>
<h1>Touchable</h1>
<p>Touchable is a very lightweight (1,96kb) jQuery Class that unifies touch and mouse events over different platforms like desktops and mobile devices with touchscreens (like Android, iPad, iPod Touch, iPhone etc.)
The name Touchable therefore might be a bit confusing, cause we actually generate a generic "Touch" which involves also mouse events. For convenience they are all called "Touches".</p>
<p>Touchable really doesn't depend that much on jQuery, so it should work with other libraries like <a href="http://zeptojs.com/">Zepto</a> too. Havent tested that though.</p>
<h1>Hoverable</h1>
<p>Hoverable is built upon Touchable and is a very lightweight (1,57kB / 3,04 together with Touchable) jQuery Class that unifies hover events over different platforms like desktops and mobile devices with touchscreens (like Android, iPad, iPod Touch, iPhone etc.)
It introduces a new event called </p>
<ul>
<li><strong>newHover(2)</strong>: following my <a href="http://grenzgenial.com/post/2429779568/longtap-is-the-new-hover">blog article</a> about UI design and my postulate, that Long Tap is the new Hover. Fired when the user hovers with the mouse or longTaps an element. Hovever if you want to you can set it up to a touchmove event too, which will fire a genericHover2 event.</li>
</ul>
<h2>Testing</h2>
<p>right now I have tested Touchable on the following devices and browsers Chrome, Firefox, Safari, iPad Simulator, iPad, iPhone, Internet Explorer 7/8. But it should work quite everywhere. If you have any bug notes drop me a line.</p>
<h2>Demo</h2>
<p>I have setup a demo site for Hoverable on the <a href="http://dotmaster.github.com/Touchable-jQuery-Plugin/demo/demo.html">github page</a>. View source to see how everything works.</p>
<h2>Usage</h2>
<p>Right now Touchable supports five basic events and Hoverable adds two generic Hover events, all events when bound with jQuery's bind function get a touch object passed in as second argument</p>
<h1>TOUCHABLE</h1>
<ul>
<li><strong>touchablemove</strong>: fired when the user touched or clicked with the mouse and moves to another position. Right now Touchable supports up to 2 fingers. If 2 fingers are on screen the lower left is taken as a reference.</li>
<li><strong>touchableend</strong>: fired when the user ended a touch</li>
<li><strong>tap</strong>: fired when the user clicks with his mouse or taps with his finger</li>
<li><strong>longTap</strong>: fired when the user stays with his mouse or finger on an item for 1 second</li>
<li><strong>doubleTap</strong>: fired when the user taps two times within half of a second</li>
</ul>
<h1>HOVERABLE</h1>
<ul>
<li><strong>newHover(2)</strong>: Fired when the user hovers with the mouse or longTaps an element. Hovever if you want to you can set it up to a touchmove event too, which will fire a genericHover2 event.</li>
</ul>
<p>you use it by initializing Touchable on a view element, like so:</p>
<pre><code>var div = $(<div>).Touchable();
</code></pre>
<p>or</p>
<pre><code>var div = $(<div>).Hoverable(); //which cretaes a Touchable internally
</code></pre>
<p>then you bind to the events</p>
<pre><code>div.bind('touchmove', function(e, touch){})
div.bind('newHover2', function in(e, touch){}, function out(e, touch){})
</code></pre>
<p>notice, that each event gets passed a touch object, besides the normal event object. The Touch object has the following properties: </p>
<ul>
<li>startTouch: this is where the touch or mousedown event originated</li>
<li>currentTouch: this is where we are right now with our finger or mouse </li>
<li>previousTouch: for internal calculations of the previous position of the mouse pointer or finger, used for deltas see below</li>
<li>currentDelta: measured from previous move event</li>
<li>currentStartDelta, currentPosition: the relative position, measured from start calculated in different ways, but should be the same</li>
</ul>
<h2><strong>Event targets:</strong></h2>
<ul>
<li>currentTarget: the event target element (may differ on mobile browsers from the ctarget element)</li>
<li>target: the event target element</li>
</ul>
<h2>Todos</h2>
<ul>
<li>support more gestures like swiping,...</li>
</ul>