dragger.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html>
  2. <html>
  3. <!--
  4. Copyright 2010 The Closure Library Authors. All Rights Reserved.
  5. Use of this source code is governed by the Apache License, Version 2.0.
  6. See the COPYING file for details.
  7. -->
  8. <head>
  9. <title>goog.fx.Dragger</title>
  10. <script src="../base.js"></script>
  11. <script>
  12. goog.require('goog.events');
  13. goog.require('goog.events.EventType');
  14. goog.require('goog.fx.Dragger');
  15. goog.require('goog.fx.Dragger.EventType');
  16. </script>
  17. <link rel="stylesheet" href="css/demo.css">
  18. <style>
  19. #stopper {
  20. position: absolute;
  21. padding: 5px;
  22. right: 20px;
  23. top: 20px;
  24. width: 100px;
  25. height: 100px;
  26. background: pink;
  27. border: 1px solid red;
  28. }
  29. #out {
  30. display: inline;
  31. background: #eee;
  32. border: 1px solid #ddd;
  33. padding: 5px;
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <h1>goog.fx.Dragger</h1>
  39. <p>This demo shows how to use a dragger to capture mouse move events. It tests
  40. that you can drag things outside the window and that alerts ends the dragging.
  41. <h2 id=test onclick="alert('Click')">Drag me</h2>
  42. <pre id=out>Status</pre>
  43. <div id=stopper onmouseover="alert('Stop!')">Drag over me to generate an
  44. alert</div>
  45. <script>
  46. function update(e) {
  47. print(e.clientX + ', ' + e.clientY);
  48. }
  49. function print(s) {
  50. document.getElementById('out').innerHTML = s;
  51. }
  52. var testEl = document.getElementById('test');
  53. goog.events.listen(testEl, goog.events.EventType.MOUSEDOWN, function(e) {
  54. var d = new goog.fx.Dragger(testEl);
  55. d.addEventListener(goog.fx.Dragger.EventType.DRAG, function(e) {
  56. update(e);
  57. });
  58. d.addEventListener(goog.fx.Dragger.EventType.END, function(e) {
  59. print('finish');
  60. d.dispose();
  61. });
  62. d.startDrag(e);
  63. });
  64. </script>
  65. </body>
  66. </html>