Debian Codegraph @

closure-library/closure/goog/demos/wheelhandler.html

raw
1 <!DOCTYPE html>
2 <html>
3 <!--
4 Copyright 2014 The Closure Library Authors. All Rights Reserved.
5
6 Use of this source code is governed by the Apache License, Version 2.0.
7 See the COPYING file for details.
8 -->
9 <head>
10 <title>goog.events.WheelHandler</title>
11 <link rel="stylesheet" href="../css/checkbox.css">
12 <style>
13 #out {
14 background-color: #eee;
15 width: 500px;
16 height: 500px;
17 position: relative;
18 display: inline-block;
19 }
20
21 #h-line, #v-line {
22 position: absolute;
23 background: black;
24 }
25
26 #h-line {
27 width: 20px;
28 height: 1px;
29 }
30
31 #v-line {
32 width: 1px;
33 height: 20px;
34 }
35
36 #status {
37 position: absolute;
38 bottom: 0;
39 right: 0;
40 font: 70% sans-serif;
41 }
42
43 #debug {
44 font-family: monospace;
45 white-space: pre;
46 display: inline-block;
47 }
48
49 </style>
50 <script src="../base.js"></script>
51 <script>
52
53 goog.require('goog.events');
54 goog.require('goog.events.WheelHandler');
55
56 </script>
57 </head>
58 <body>
59
60 <h1>goog.events.WheelHandler</h1>
61
62 <p>Use your mousewheel on the gray box below to move the cross hair.
63
64 <div id=out>
65 <div id=h-line></div>
66 <div id=v-line></div>
67 <div id=status></div>
68 </div>
69
70 <div id=debug>
71 </div>
72
73 <script>
74
75 var WheelHandler = goog.events.WheelHandler;
76 var WHEEL = WheelHandler.EventType.WHEEL;
77
78 function $(id) {
79 return document.getElementById(id)
80 }
81
82 var x = 250, y = 250;
83 var out = $('out');
84 var hLine= $('h-line');
85 var vLine = $('v-line');
86 var statusLine = $('status');
87 var debug = $('debug');
88
89 var availWidth = out.clientWidth - vLine.offsetWidth;
90 var availHeight = out.clientHeight - hLine.offsetHeight;
91
92 function handleWheel(e) {
93 x += e.pixelDeltaX;
94 x = Math.max(0, Math.min(availWidth, x));
95 y += e.pixelDeltaY;
96 y = Math.max(0, Math.min(availHeight, y));
97 updateLines();
98 e.preventDefault();
99 var deltaModeString = 'unknown';
100 var DeltaMode = goog.events.WheelHandler.DeltaMode;
101 switch (e.deltaMode) {
102 case DeltaMode.PIXEL:
103 deltaModeString = 'DeltaMode.PIXEL';
104 break;
105 case DeltaMode.LINE:
106 deltaModeString = 'DeltaMode.LINE';
107 break;
108 case DeltaMode.PAGE:
109 deltaModeString = 'DeltaMode.PAGE';
110 break;
111 }
112 var debugObject = {
113 type: e.type,
114 deltaMode: deltaModeString,
115 deltaX: e.deltaX,
116 deltaY: e.deltaY,
117 deltaZ: e.deltaZ,
118 pixelDeltaX: e.pixelDeltaX,
119 pixelDeltaY: e.pixelDeltaY,
120 pixelDeltaZ: e.pixelDeltaZ,
121 };
122 debug.innerText = JSON.stringify(debugObject, undefined, 4);
123 }
124
125 function updateLines() {
126 vLine.style.left = x + 'px';
127 hLine.style.left = x - hLine.offsetWidth / 2 + 'px';
128 hLine.style.top = y + 'px';
129 vLine.style.top = y - vLine.offsetHeight / 2 + 'px';
130 statusLine.innerText = x + ', ' + y;
131 }
132
133 updateLines();
134
135 var mwh = new WheelHandler(out);
136 goog.events.listen(mwh, WHEEL, handleWheel);
137
138 goog.events.listen(window, 'unload', function(e) {
139 goog.events.unlisten(mwh, WHEEL, handleWheel);
140 });
141
142 </script>
143 </body>
144 </html>