-
Notifications
You must be signed in to change notification settings - Fork 0
/
drag.html
186 lines (158 loc) · 7.21 KB
/
drag.html
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<!-- saved from url=(0026)http://html5demos.com/drag -->
<html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta name="viewport" content="width=620">
<title>HTML5 Demo: Drag and drop</title>
<link rel="stylesheet" href="http://html5demos.com/css/html5demos.css">
<script type="text/javascript" async="" src="./drag_files/azcarbon_2_1_0_VERT"></script><script src="./drag_files/h5utils.js"></script><script id="_carbonads_projs" type="text/javascript" src="./drag_files/C6AILKT.json"></script><style>.carbonad{background-color:#FBFBFB;border:2px solid #E8E8E8;height:215px;line-height:1.2;width:150px}.carbonad-img{float:left;height:100px;margin-left:11px;margin-top:11px;width:130px}.carbonad-text{color:#545454;float:left;font-family:Arial,Helvetica,sans-serif;font-size:11px;font-weight:400;height:50px;margin-left:15px;margin-top:9px;width:119px}.carbonad-text a{color:#545454;text-decoration:none;text-transform:none;}.carbonad-tag{color:#999;float:left;font-family:Arial,Helvetica,sans-serif;font-size:11px;font-weight:400;margin-left:17px;margin-top:15px;padding-top:5px}.carbonad-tag a{color:#999;text-align:center;text-decoration:none;font-weight:700}</style></head>
<body>
<section id="wrapper">
<div id="carbonads-container"><div class="carbonad"><div id="azcarbon"><span><span class="carbonad-image"><a href="http://srv.carbonads.net/ads/click/x/GTND423JCVYDK23WCWB4YKQWC67DT2QMCYADTZ3JCEYI6K3MF6YDKK3KC6BD4KJECYBDTK3EHJNCLSIZ?segment=placement:html5demoscom" target="_blank"><img width="130" height="100" border="0" src="./drag_files/16903" class="carbonad-image carbonad-img"></a></span><span class="carbonad-text"><a href="http://srv.carbonads.net/ads/click/x/GTND423JCVYDK23WCWB4YKQWC67DT2QMCYADTZ3JCEYI6K3MF6YDKK3KC6BD4KJECYBDTK3EHJNCLSIZ?segment=placement:html5demoscom">The Stormpath API automates user management so you can build your Node application faster.</a></span><span class="carbonad-tag">ads via <a href="http://carbonads.com/">Carbon</a></span></span></div><script type="text/javascript">var z = document.createElement("script"); z.type = "text/javascript"; z.async = true; z.src = "http://engine.carbonads.com/z/14060/azcarbon_2_1_0_VERT"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s);</script></div></div>
<header>
<h1>Drag and drop</h1>
</header>
<style type="text/css">
li {
list-style: none;
}
li a {
text-decoration: none;
color: #000;
margin: 10px;
width: 150px;
border: 3px dashed #999;
background: #eee;
padding: 10px;
display: block;
}
*[draggable=true] {
-moz-user-select:none;
-khtml-user-drag: element;
cursor: move;
}
*:-khtml-drag {
background-color: rgba(238,238,238, 0.5);
}
li a:hover:after {
content: ' (drag me)';
}
ul {
margin-left: 200px;
min-height: 300px;
}
li.over {
border-color: #333;
background: #ccc;
}
#bin {
background: url(images/bin.jpg) top right no-repeat;
height: 250px;
width: 166px;
float: left;
border: 5px solid #000;
position: relative;
margin-top: 0;
}
#bin.over {
background: url(images/bin.jpg) top left no-repeat;
}
#bin p {
font-weight: bold;
text-align: center;
position: absolute;
bottom: 20px;
width: 166px;
font-size: 32px;
color: #fff;
text-shadow: #000 2px 2px 2px;
}
</style>
<div id="log"></div>
<article>
<p>Drag the list items over the dustbin, and drop them to have the bin eat the item</p>
<div id="bin" class="over"></div>
<ul>
<li><a id="one" href="#" draggable="true">one</a></li>
<li><a href="#" id="two" draggable="true">two</a></li>
<li><a href="#" id="three" draggable="true">three</a></li>
<li><a href="#" id="four" draggable="true">four</a></li>
<li><a href="#" id="five" draggable="true">five</a></li>
</ul>
</article>
<script>
function logit(msg) { document.getElementById('log').innerHTML += msg + '<br/>'; }
var eat = ['yum!', 'gulp', 'burp!', 'nom'];
var yum = document.createElement('p');
var msie = /*@cc_on!@*/0;
yum.style.opacity = 1;
var links = document.querySelectorAll('li > a'), el = null;
for (var i = 0; i < links.length; i++) {
el = links[i];
el.setAttribute('draggable', 'true');
addEvent(el, 'dragstart', function (e) {
e.dataTransfer.effectAllowed = 'copy'; // only dropEffect='copy' will be dropable
logit("setting id: " + this.id);
e.dataTransfer.setData('Text', this.id); // required otherwise doesn't work
});
}
var bin = document.querySelector('#bin');
addEvent(bin, 'dragover', function (e) {
if (e.preventDefault) e.preventDefault(); // allows us to drop
this.className = 'over';
e.dataTransfer.dropEffect = 'copy';
return false;
});
// to get IE to work
addEvent(bin, 'dragenter', function (e) {
this.className = 'over';
return false;
});
addEvent(bin, 'dragleave', function () {
this.className = '';
});
addEvent(bin, 'drop', function (e) {
if (e.stopPropagation) e.stopPropagation(); // stops the browser from redirecting...why???
if (e.preventDefault) e.preventDefault();
// alert(e.dataTransfer.getData('Text'));
logit("getting id: " + e.dataTransfer.getData('Text'));
var el = document.getElementById(e.dataTransfer.getData('Text'));
// alert(el);
el.parentNode.removeChild(el);
// stupid nom text + fade effect
bin.className = '';
yum.innerHTML = eat[parseInt(Math.random() * eat.length)];
var y = yum.cloneNode(true);
bin.appendChild(y);
setTimeout(function () {
var t = setInterval(function () {
if (y.style.opacity <= 0) {
if (msie) { // don't bother with the animation
y.style.display = 'none';
}
clearInterval(t);
} else {
y.style.opacity -= 0.1;
}
}, 50);
}, 250);
return false;
});
</script>
<a id="html5badge" href="http://www.w3.org/html/logo/">
<img src="./drag_files/html5-badge-h-connectivity-device-graphics-multimedia-performance-semantics-storage.png" width="325" height="64" alt="HTML5 Powered with Connectivity / Realtime, Device Access, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage" title="HTML5 Powered with Connectivity / Realtime, Device Access, Graphics, 3D & Effects, Multimedia, Performance & Integration, Semantics, and Offline & Storage">
</a>
<footer><a href="http://html5demos.com/">HTML5 demos</a>/<a id="built" href="http://twitter.com/rem">@rem built this</a>/<a href="http://html5demos.com/drag#view-source">view source</a></footer>
</section>
<a href="http://github.com/remy/html5demos"><img style="position: absolute; top: 0; left: 0; border: 0;" src="./drag_files/forkme_left_darkblue_121621.png" alt="Fork me on GitHub"></a>
<script src="./drag_files/prettify.packed.js"></script>
<script>
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><script src="./drag_files/ga.js" type="text/javascript"></script>
<script>
try {
var pageTracker = _gat._getTracker("UA-1656750-18");
pageTracker._trackPageview();
} catch(err) {}</script>
</body></html>