Drag and Click

The Demo Webpage to Tell Drag and Click

Sometimes it’s not that intuitive to tell drag and click event, as both of them are detecting mousedown event. The following script handles this problem, and provide basic drag and click functions.

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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="UTF-8" />
<meta view-port="width=device-width, initial-scale" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<head>
<style>
#box1, #box2, #box3, #box4, #box5, #box6 {
position: absolute;
}

* {
margin: 0;
padding: 0;
}

body {
font-size: 100%;
margin: 3em;

}

h2, p {
font-size: 100%;
font-weight: normal;
}

ul, li {
list-style: none;
}

ul {
overflow: hidden;
padding: 3em;
}

ul li a {
text-decoration: none;
color: #000;
background: #F1F1F1;
display: block;
height: 350px;
width: 280px;
padding: 1em;
/* Firefox */
-moz-box-shadow: 5px 5px 7px rgba(20, 20, 20, 1);
/* Safari+Chrome */
-webkit-box-shadow: 5px 5px 7px rgba(20, 20, 20, .5);
/* Opera */
box-shadow: 5px 5px 7px rgba(20, 20, 20, .5);
-webkit-transform: rotate(-6deg);
-o-transform: rotate(-6deg);
-moz-transform: rotate(-6deg);
-moz-transition: -moz-transform .15s linear;
-o-transition: -o-transform .15s linear;
-webkit-transition: -webkit-transform .15s linear;
}

ul li {
margin: 1em;
float: left;
}

ul li h2 {
font-size: 140%;
font-weight: bold;
padding-bottom: 20px;
}

ul li p {
font-size: 120%;
}

.contact-info {
position: fixed;
top: 40%;
z-index: 99999;
left: 0;

}

.option {
cursor: pointer;
position: relative;
}

.option i {
display: block;
width: 60px;
text-align: center;
height: 60px;
line-height: 60px;
background: #f1f1f1;
color: #b9b9b9;
font-size: 20px;
}

.option:hover i {
color: #6F7784;
}

.text {
position: absolute;
height: 60px;
width: 120px;
background: #6F7784;
top: 0;
z-index: -1;
left: -140px;
color: #f2e9e1;
line-height: 60px;
text-align: center;
transition: left 0.6s;
}

.option:hover .text {
left: 60px;
}
</style>

<script type="text/javascript">
var noClick = false;
window.onload = function () {
var box1 = document.getElementById("box1");
var box2 = document.getElementById("box2");
var box3 = document.getElementById("box3");
var box4 = document.getElementById("box4");
var box5 = document.getElementById("box5");
var box6 = document.getElementById("box6");
drag(box1);
drag(box2);
drag(box3);
drag(box4);
drag(box5);
drag(box6);
function drag(obj) {
console.log(123);
obj.onmousedown = function (event) {
obj.setCapture && obj.setCapture();
event = event || window.event;

var ol = event.clientX - obj.offsetLeft;
var ot = event.clientY - obj.offsetTop;

document.onmousemove = function (event) {
noClick = true;
event = event || window.event;
var left = event.clientX - ol;
var top = event.clientY - ot;
obj.style.left = left + "px";
obj.style.top = top + "px";
return false;
};

document.onmouseup = function (e) {
document.onmousemove = null;
document.onmouseup = null;
obj.releaseCapture && obj.releaseCapture();
return false;
};

return false;
};
obj.onclick = function (event){
if(noClick){
noClick = false;
event.preventDefault();
return false;
}
}
}
}
</script>
</head>
<body>
<ul>
<li>
<a href="javascript:alert('Hi, you clicked me!');" id="box1">
<h2>Wednesday 6th September, 10:36pm</h2>
<p>
1, I have continued trade talks with Iran.
<br>
2, Replied to Trump about stuff.
<br>
3, Followed up on trade deals with Israel.
<br>
4, Started hopeful trade deals with Egypt.
</p>
</a>
</li>
<li>
<a href="javascript:alert('Hi, you clicked me!');" id="box2">
<h2>Wednesday 6th September, 7:22pm</h2>
<p>
Things to do...
<br>
1, follow up trade deals and Arms deals in case people have forgotten i.e., Israel, Turkey, Libya and Egypt
</p>
</a>
</li>
<li>
<a href="javascript:alert('Hi, you clicked me!');" id="box3">
<h2>Monday 4th September, 5:09pm</h2>
<p>
Important: We decided to have a meeting at 7pm Tuesday to discuss Israel-Palestine conflict.
</p>
</a>
</li>
<li>
<a href="javascript:alert('Hi, you clicked me!');" id="box4">
<h2>Sunday 3rd September, 5:37pm</h2>
<p>
1, I have assured Morocco that we support them in their ownership of the Western Sahara.
<br>
2, Also, have tweeted about it and contacted all media issuing a statement that we support Morocco
</p>
</a>
</li>
<li>
<a href="javascript:alert('Hi, you clicked me!');" id="box5">
<h2>Saturday 2nd September, 4:56pm</h2>
<p>
I have continued trade talks with Saudi Arabia, Israel and Morocco. No response yet. I have also added the
trade talks tags to each of the emails and archived them.
</p>
</a>
</li>
<li>
<a href="javascript:alert('Hi, you clicked me!');" id="box6">
<h2>Saturday 2nd September, 2:48pm</h2>
<p>I'll do Algeria, Libya and Iran
<br>
you can do Saudi, Israel and Morocco
<br>
then we need to talk more with the European leaders let's try start talks with them about Syria and say we don't
believe a ceasefire will work
</p>
</a>
</li>

</ul>

<!-- set a side bar -->
<div class="contact-info">
<div class="option">
<i class="fa fa-home"></i>
<a class="text" href="#">Home</a>
</div>
<div class="option">
<i class="fa fa-envelope"></i>
<a class="text" href="email">Email</a>
</div>
<div class="option">
<i class="fab fa-twitter-square"></i>
<a class="text" href="tweet">Tweet</a>
</div>
<div class="option">
<i class="fas fa-newspaper"></i>
<a class="text" href="news">News</a>
</div>
<div class="option">
<i class="fas fa-comment-alt"></i>
<a class="text" href="chat">Chat</a>
</div>
<div class="option">
<i class="fa fa-cog"></i>
<a class="text" href="control">Control</a>
</div>
</div>

</body>
</html>