dragscrollsupport.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.DragScrollSupport</title>
  10. <meta charset="utf-8">
  11. <script src="../base.js"></script>
  12. <script>
  13. goog.require('goog.fx.DragDrop');
  14. goog.require('goog.fx.DragDropGroup');
  15. goog.require('goog.fx.DragScrollSupport');
  16. goog.require('goog.dom');
  17. </script>
  18. <link rel="stylesheet" href="css/demo.css">
  19. <style>
  20. body {
  21. margin: 10px;
  22. }
  23. ul {
  24. padding: 0px;
  25. }
  26. li {
  27. list-style: none;
  28. }
  29. li, div {
  30. font: menu;
  31. width: 20ex;
  32. border: 1px solid gray;
  33. margin: 1px;
  34. padding: 0px 2px 0px 2px;
  35. background: silver;
  36. }
  37. .source {
  38. cursor: move;
  39. -moz-user-select: none;
  40. }
  41. .drag {
  42. cursor: move;
  43. background: green;
  44. }
  45. .target {
  46. }
  47. #list2 {
  48. margin: 0px 30px 30px 30px;
  49. padding-left: 30px;
  50. }
  51. .foo {
  52. position: absolute;
  53. background: pink;
  54. padding: 5px;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <h1>goog.fx.DragScrollSupport</h1>
  60. List 1 in a scrollable area.
  61. <div id="list1-container" style="overflow:scroll; width: 100px; height: 300px;">
  62. <ul id="list1">
  63. <li>Item 1.1 ----------</li>
  64. <li>Item 1.2 ----------</li>
  65. <li>Item 1.3 ----------</li>
  66. <li>Item 1.4 ----------</li>
  67. <li>Item 1.5 ----------</li>
  68. <li>Item 1.6 ----------</li>
  69. <li>Item 1.7 ----------</li>
  70. <li>Item 1.8 ----------</li>
  71. <li>Item 1.9 ----------</li>
  72. <li>Item 1.10 ----------</li>
  73. <li>Item 1.11 ----------</li>
  74. <li>Item 1.12 ----------</li>
  75. <li>Item 1.13 ----------</li>
  76. <li>Item 1.14 ----------</li>
  77. <li>Item 1.15 ----------</li>
  78. </ul>
  79. </div>
  80. <script>
  81. var scrollSupport = null;
  82. var list1 = new goog.fx.DragDropGroup();
  83. var nodes = document.getElementById('list1').childNodes;
  84. var len = nodes.length;
  85. for (var i = 0; i < len; i++) {
  86. var el = nodes[i];
  87. if ((el.nodeType == 1) && (el.nodeName == 'LI')) {
  88. list1.addItem(el, el.firstChild.nodeValue);
  89. }
  90. }
  91. list1.addScrollableContainer(goog.dom.getElement('list1-container'));
  92. list1.addTarget(list1);
  93. // Set additional classes used to indicate dragging
  94. list1.setSourceClass('source');
  95. list1.setTargetClass('target');
  96. // Init drag objects
  97. list1.init();
  98. // Set up event handlers
  99. goog.events.listen(list1, 'dragover', dragOver);
  100. goog.events.listen(list1, 'dragout', dragOut);
  101. goog.events.listen(list1, 'dragstart', dragStart);
  102. goog.events.listen(list1, 'dragend', dragEnd);
  103. function dragOver(event) {
  104. event.dropTargetItem.element.style.background = 'red';
  105. }
  106. function dragOut(event) {
  107. event.dropTargetItem.element.style.background = 'silver';
  108. }
  109. function dragStart(event) {
  110. goog.style.setOpacity(event.dragSourceItem.element, 0.5);
  111. scrollSupport = new goog.fx.DragScrollSupport(
  112. goog.dom.getElement('list1-container'));
  113. }
  114. function dragEnd(event) {
  115. goog.style.setOpacity(event.dragSourceItem.element, 1.0);
  116. goog.dispose(scrollSupport);
  117. }
  118. </script>
  119. </body>
  120. </html>