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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
<!DOCTYPE html>
<html>
<!--
Copyright 2010 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
-->
<head>
<title>goog.fx.DragScrollSupport</title>
<meta charset="utf-8">
<script src="../base.js"></script>
<script>
goog.require('goog.fx.DragDrop');
goog.require('goog.fx.DragDropGroup');
goog.require('goog.fx.DragScrollSupport');
goog.require('goog.dom');
</script>
<link rel="stylesheet" href="css/demo.css">
<style>
body {
margin: 10px;
}
ul {
padding: 0px;
}
li {
list-style: none;
}
li, div {
font: menu;
width: 20ex;
border: 1px solid gray;
margin: 1px;
padding: 0px 2px 0px 2px;
background: silver;
}
.source {
cursor: move;
-moz-user-select: none;
}
.drag {
cursor: move;
background: green;
}
.target {
}
#list2 {
margin: 0px 30px 30px 30px;
padding-left: 30px;
}
.foo {
position: absolute;
background: pink;
padding: 5px;
}
</style>
</head>
<body>
<h1>goog.fx.DragScrollSupport</h1>
List 1 in a scrollable area.
<div id="list1-container" style="overflow:scroll; width: 100px; height: 300px;">
<ul id="list1">
<li>Item 1.1 ----------</li>
<li>Item 1.2 ----------</li>
<li>Item 1.3 ----------</li>
<li>Item 1.4 ----------</li>
<li>Item 1.5 ----------</li>
<li>Item 1.6 ----------</li>
<li>Item 1.7 ----------</li>
<li>Item 1.8 ----------</li>
<li>Item 1.9 ----------</li>
<li>Item 1.10 ----------</li>
<li>Item 1.11 ----------</li>
<li>Item 1.12 ----------</li>
<li>Item 1.13 ----------</li>
<li>Item 1.14 ----------</li>
<li>Item 1.15 ----------</li>
</ul>
</div>
<script>
var scrollSupport = null;
var list1 = new goog.fx.DragDropGroup();
var nodes = document.getElementById('list1').childNodes;
var len = nodes.length;
for (var i = 0; i < len; i++) {
var el = nodes[i];
if ((el.nodeType == 1) && (el.nodeName == 'LI')) {
list1.addItem(el, el.firstChild.nodeValue);
}
}
list1.addScrollableContainer(goog.dom.getElement('list1-container'));
list1.addTarget(list1);
// Set additional classes used to indicate dragging
list1.setSourceClass('source');
list1.setTargetClass('target');
// Init drag objects
list1.init();
// Set up event handlers
goog.events.listen(list1, 'dragover', dragOver);
goog.events.listen(list1, 'dragout', dragOut);
goog.events.listen(list1, 'dragstart', dragStart);
goog.events.listen(list1, 'dragend', dragEnd);
function dragOver(event) {
event.dropTargetItem.element.style.background = 'red';
}
function dragOut(event) {
event.dropTargetItem.element.style.background = 'silver';
}
function dragStart(event) {
goog.style.setOpacity(event.dragSourceItem.element, 0.5);
scrollSupport = new goog.fx.DragScrollSupport(
goog.dom.getElement('list1-container'));
}
function dragEnd(event) {
goog.style.setOpacity(event.dragSourceItem.element, 1.0);
goog.dispose(scrollSupport);
}
</script>
</body>
</html>
|