-
Notifications
You must be signed in to change notification settings - Fork 29
/
index.html
93 lines (86 loc) · 5.3 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
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="utf-8">
<title>Hammer Time</title>
<link href='http://fonts.googleapis.com/css?family=Hammersmith+One' rel='stylesheet' type='text/css'>
<link href="demo.css" rel="stylesheet" type="text/css">
<script src="hammer-time.js"></script>
<script src="https://code.jquery.com/jquery-1.11.3.js"></script>
<script>
$(function(){
var upEvent = window.PointerEvent ? "pointerup" : ( ( 'ontouchstart' in window ) || window.DocumentTouch && document instanceof DocumentTouch ) ? "touchend" : "mouseup";
$( ".target" ).on( upEvent, function( e ) {
this.startTime = Date.now();
$( this ).find( ".output" ).html( e.type + ": " + this.startTime + "<br>");
} );
$( ".target" ).on( "click", function( e ) {
var now = Date.now();
var clickTime = now - this.startTime;
var target = $( this );
var status = clickTime < 100 ? "" : clickTime < 300 ? "warning" : "failure"
target.find( ".click-gauge" )
.attr( "value", clickTime )
.removeClass( "failure success" )
.addClass( status );
target.find( ".click-time-output" ).text( clickTime + "ms" );
target.find( ".output" ).append( "click: " + now + "<br>");
$( this ).addClass( "clicked" );
setTimeout( function() {
$( this ).removeClass( "clicked" );
}.bind( this ), 1000 )
} );
});
</script>
</head>
<body>
<div class="body-wrap">
<h1 class="title">Hammer Time!</h1>
<img class="hero" alt="Thors Hammer crashing down" src="http://33.media.tumblr.com/85d64e2f846797ab471480cff3f33d4b/tumblr_mzms7yMfum1s75u1lo2_500.gif">
<h2 class="title-2">On your click times!</h2>
<h4>Response time on user actions is important</h4>
<p>Keeping visual response to under 100ms means your users will not notice the delay. The UI will feel quick and responsive giving users the impression they are doing the work instead of the application. Try the boxes below to see the response time on mobile devices.</p>
<p>The first box uses <code>touch-action:none;</code> to remove the 300ms delay. The second box has no <code>touch-action</code> property set. On touch screens you will see a noticeable difference in the response time of the background and in the outputing of the end vs click events.</p>
<div id="wrap">
<div class="target-wrap" id="target">
<div class="target" style="touch-action: none;">
<code>style="touch-action: none;"</code><br>
Click Time: <span class="click-time-output">0ms</span>
<progress class="click-gauge" max="500" value="0"></progress>
<span class="output"></span>
<div class="hit-target"></div>
</div>
</div>
<div class="target-wrap">
<div class="target">
<code>style=""</code><br>
Click Time: <span class="click-time-output">0ms</span>
<progress class="click-gauge" max="500" value="0"></progress>
<span class="output"></span>
<div class="hit-target" style=""></div>
</div>
</div>
</div>
<p>The <code>touch-action</code> css property is part of the Pointer Events spec <a href="http://www.w3.org/TR/pointerevents/#the-touch-action-css-property">http://www.w3.org/TR/pointerevents/#the-touch-action-css-property</a>
<p>Unfourtanitly not all common browsers support touch action yet ( <a href="http://caniuse.com/#feat=css-touch-action">caniuse</a> ) so hammer-time works by partially polyfills this property. The only supported value is <code>none</code>, <code>manipulation</code>, or <code>auto</code></p>
<h3>Advantages...</h3>
<ul>
<li>Size Hammer-time is very very small only 417 bytes gzipped</li>
<li>Easy to use no special libraries or events to bind. Hammer-time just speeds up the native events so you can use your favorite event library like jQuery or just plain old <code>addEventListener</code></li>
<li>Based on real standards, Hammer-time is a polyfill so it is a complete noop on browsers which support native <code>touch-action</code></li>
<li>Avoids target mismatches between the <code>touchend</code> and <code>click</code> events</li>
</ul>
<h3>Gotchas...</h3>
<ul>
<li><b>Only works when applied directly to the style attribute on an element not to a stylesheet</b></li>
<li>Does not prevent scrolling or other behivors which happen on move or double tap zoom</li>
<li>You cannot set the touch-action property via `element.style[ touch-action ]` browsers that do not support touch action will ignore this</li>
<li>Removing the touch-action property from an existing element is not supported, Hammer-time has no way of knowing the difference between you removing the property and it being removed as a result or browser sanitization. Instead of removng the property completely simply change it to the default value of auto</li>
<li>Direct manipulation of the style property in a loop on elements with touch-action set from JavaScript ( JS animations for example ) should be avoided. Because of how browsers sanitize the style attribute when setting properties we use a mutation observe to restore the the touch action property when it is removed</li>
<li>To properly support IE10 you need to add both <code>touch-action</code> and <code>-ms-touch-action</code>
</ul>
<cite>To read more about UI response times and how this effects user experience see <a href="http://www.nngroup.com/articles/response-times-3-important-limits/">http://www.nngroup.com/articles/response-times-3-important-limits/</a></cite>
</div>
</body>
</html>