5 <meta name=
"viewport" content=
"width=device-width,initial-scale=1">
6 <title>Touch handler dragging
</title>
8 <style type=
"text/css">
10 background-color: blue
;
11 border: 1px solid black
;
18 This test case drags a div on touch move events. This serves as the baseline
19 of latency measurement for pages with non-empty JS touch handler.
26 function startExperiment() {
27 card
= document
.getElementById('card');
28 card
.addEventListener('touchstart', onTouchStart
, false);
29 card
.addEventListener('touchmove', onTouchMove
, false);
30 card
.addEventListener('touchend', onTouchEnd
, false);
31 card
.addEventListener('touchcancel', onTouchEnd
, false);
34 window
.addEventListener('load', startExperiment
);
36 function onTouchStart(e
) {
37 var touch
= e
.targetTouches
[0];
38 startX
= touch
.clientX
;
39 startY
= touch
.clientY
;
43 function onTouchMove(e
) {
44 var touch
= e
.targetTouches
[0];
45 deltaX
= touch
.clientX
- startX
;
46 deltaY
= touch
.clientY
- startY
;
47 window
.requestAnimationFrame(onAnimationTouchMove
);
51 function onAnimationTouchMove() {
52 card
.style
.webkitTransform
= 'translate(' + deltaX
+ 'px, ' + deltaY
+ 'px)';
55 function onTouchEnd(e
) {
56 window
.requestAnimationFrame(onAnimationTouchEnd
);
60 function onAnimationTouchEnd() {
61 card
.style
.webkitTransform
= '';