質問編集履歴
4
加筆
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,12 @@
|
|
18
18
|
|
19
19
|
jQueryを使わず、ドラッグアンドドロップによるパーツの並び替えを実装をしたい。
|
20
20
|
|
21
|
+
参考サイトを見てみると、clickした要素に`darggable=true`を付与するだけで移動、並び替えをしています。
|
22
|
+
|
23
|
+
id,data属性を付与せずにdndを実装する方法はありませんでしょうか?
|
24
|
+
|
25
|
+
|
26
|
+
|
21
27
|
|
22
28
|
|
23
29
|
**何のためにしたいか**
|
@@ -28,9 +34,11 @@
|
|
28
34
|
|
29
35
|
|
30
36
|
|
37
|
+
参考サイトでは、
|
38
|
+
|
31
|
-
|
39
|
+
パーツパレットからiframeへパーツをdndしてモックアップを作成することができます。
|
32
|
-
|
40
|
+
|
33
|
-
|
41
|
+
パーツパレットからの移動だけでなく、ドロップ後、iframe内でもパーツの移動、並び替えができます。
|
34
42
|
|
35
43
|
|
36
44
|
|
3
実現したいことを加筆
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,13 +14,29 @@
|
|
14
14
|
|
15
15
|
## 実現したいこと
|
16
16
|
|
17
|
+
**何をしたいか**
|
18
|
+
|
17
|
-
|
19
|
+
jQueryを使わず、ドラッグアンドドロップによるパーツの並び替えを実装をしたい。
|
20
|
+
|
21
|
+
|
22
|
+
|
18
|
-
|
23
|
+
**何のためにしたいか**
|
24
|
+
|
25
|
+
下記参考サイトの簡易版を作成したい。
|
26
|
+
|
27
|
+
参考: [pingendo https://v40.pingendo.com/new](https://v40.pingendo.com/new)
|
28
|
+
|
29
|
+
|
30
|
+
|
19
|
-
|
31
|
+
参考サイトでは、パーツパレットからiframeへパーツをdndしてモックアップを作成することができます。
|
32
|
+
|
20
|
-
|
33
|
+
このサイトでは、パーツパレットからの移動だけでなく、ドロップ後、iframe内でもパーツの移動、並び替えができます。
|
34
|
+
|
35
|
+
|
36
|
+
|
21
|
-
現
|
37
|
+
私が実現したいのは後者の、選択したパーツの移動ができる実装をしたいです。
|
22
|
-
|
23
|
-
|
38
|
+
|
39
|
+
|
24
40
|
|
25
41
|
|
26
42
|
|
2
実装を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -57,3 +57,345 @@
|
|
57
57
|
## 試したこと
|
58
58
|
|
59
59
|
[自分の実装jsfiddle https://jsfiddle.net/juubee/6v3xfd76/](https://jsfiddle.net/juubee/6v3xfd76/)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
- insidednd.js
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
```js:insidednd.js
|
68
|
+
|
69
|
+
const textToNode = (htmlString) => {
|
70
|
+
|
71
|
+
let tempDiv = document.createElement('div');
|
72
|
+
|
73
|
+
tempDiv.innerHTML = htmlString.trim();
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
return tempDiv.firstChild;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
const documentBody = document.body;
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
documentBody.onclick = (e) => {
|
90
|
+
|
91
|
+
e.target.setAttribute('draggable', true);
|
92
|
+
|
93
|
+
};
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
documentBody.ondragstart = (e) => {
|
98
|
+
|
99
|
+
console.log("Drag Started");
|
100
|
+
|
101
|
+
const insertingHTML = e.target.outerHTML;
|
102
|
+
|
103
|
+
e.dataTransfer.setData("Text", insertingHTML);
|
104
|
+
|
105
|
+
};
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
documentBody.ondragend = (e) => {
|
110
|
+
|
111
|
+
console.log("Drag End");
|
112
|
+
|
113
|
+
};
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
documentBody.ondragover = (e) => {
|
118
|
+
|
119
|
+
// console.log('Dragover');
|
120
|
+
|
121
|
+
e.preventDefault();
|
122
|
+
|
123
|
+
e.stopPropagation();
|
124
|
+
|
125
|
+
};
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
documentBody.ondrop = (e) => {
|
130
|
+
|
131
|
+
console.log('Drop event');
|
132
|
+
|
133
|
+
e.preventDefault();
|
134
|
+
|
135
|
+
e.stopPropagation();
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
const htmlString = e.dataTransfer.getData('text');
|
140
|
+
|
141
|
+
const node = textToNode(htmlString);
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
e.target.appendChild(node);
|
146
|
+
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
- dnd.html
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
```html: dnd.html
|
160
|
+
|
161
|
+
<html lang="ja">
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
<head>
|
166
|
+
|
167
|
+
<meta charset="utf-8">
|
168
|
+
|
169
|
+
<meta content="IE=edge" http-equiv="X-UA-Compatible">
|
170
|
+
|
171
|
+
<meta content="" name="description">
|
172
|
+
|
173
|
+
<meta content="width=device-width, initial-scale=1, shrink-to-fit=no" name="viewport">
|
174
|
+
|
175
|
+
<title>HTML5 dnd</title>
|
176
|
+
|
177
|
+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
178
|
+
|
179
|
+
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
|
180
|
+
|
181
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
|
182
|
+
|
183
|
+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
</head>
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
<body>
|
192
|
+
|
193
|
+
<div class="container">
|
194
|
+
|
195
|
+
<div class="row" >
|
196
|
+
|
197
|
+
<div class="col-12" >
|
198
|
+
|
199
|
+
<header >
|
200
|
+
|
201
|
+
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
202
|
+
|
203
|
+
<a class="navbar-brand" href="#">Navbar</a>
|
204
|
+
|
205
|
+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
206
|
+
|
207
|
+
<span class="navbar-toggler-icon"></span>
|
208
|
+
|
209
|
+
</button>
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
214
|
+
|
215
|
+
<ul class="navbar-nav mr-auto">
|
216
|
+
|
217
|
+
<li class="nav-item active">
|
218
|
+
|
219
|
+
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
|
220
|
+
|
221
|
+
</li>
|
222
|
+
|
223
|
+
<li class="nav-item">
|
224
|
+
|
225
|
+
<a class="nav-link" href="#">Link</a>
|
226
|
+
|
227
|
+
</li>
|
228
|
+
|
229
|
+
<li class="nav-item dropdown">
|
230
|
+
|
231
|
+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
|
232
|
+
|
233
|
+
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
|
234
|
+
|
235
|
+
<a class="dropdown-item" href="#">Action</a>
|
236
|
+
|
237
|
+
<a class="dropdown-item" href="#">Another action</a>
|
238
|
+
|
239
|
+
<div class="dropdown-divider"></div>
|
240
|
+
|
241
|
+
<a class="dropdown-item" href="#">Something else here</a>
|
242
|
+
|
243
|
+
</div>
|
244
|
+
|
245
|
+
</li>
|
246
|
+
|
247
|
+
<li class="nav-item">
|
248
|
+
|
249
|
+
<a class="nav-link disabled" href="#">Disabled</a>
|
250
|
+
|
251
|
+
</li>
|
252
|
+
|
253
|
+
</ul>
|
254
|
+
|
255
|
+
<form class="form-inline my-2 my-lg-0">
|
256
|
+
|
257
|
+
<input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
|
258
|
+
|
259
|
+
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
|
260
|
+
|
261
|
+
</form>
|
262
|
+
|
263
|
+
</div>
|
264
|
+
|
265
|
+
</nav>
|
266
|
+
|
267
|
+
</header>
|
268
|
+
|
269
|
+
</div>
|
270
|
+
|
271
|
+
</div>
|
272
|
+
|
273
|
+
<div class="row" >
|
274
|
+
|
275
|
+
<div class="col-9" >
|
276
|
+
|
277
|
+
<div class="row" >
|
278
|
+
|
279
|
+
<div class="col-6" >
|
280
|
+
|
281
|
+
<div class="table-responsive" >
|
282
|
+
|
283
|
+
<table class="table table-bordered table-striped mb-3 small">
|
284
|
+
|
285
|
+
<thead>
|
286
|
+
|
287
|
+
<tr>
|
288
|
+
|
289
|
+
<th scope="col">Component</th>
|
290
|
+
|
291
|
+
</tr>
|
292
|
+
|
293
|
+
</thead>
|
294
|
+
|
295
|
+
<tbody>
|
296
|
+
|
297
|
+
<tr>
|
298
|
+
|
299
|
+
<td class="align-middle p-0"><a href="project-show.html"><img class="mr-3" data-src="holder.js/80x60?theme=noimage" width="80" height="60" alt=" [80x60]" style="width: 80px; height: 60px;" >Component</a></td>
|
300
|
+
|
301
|
+
</tr>
|
302
|
+
|
303
|
+
<tr>
|
304
|
+
|
305
|
+
<td class="align-middle p-0"><a href="project-show.html"><img class="mr-3" data-src="holder.js/80x60?theme=noimage" width="80" height="60" alt=" [80x60]" style="width: 80px; height: 60px;" >Component</a></td>
|
306
|
+
|
307
|
+
</tr>
|
308
|
+
|
309
|
+
<tr>
|
310
|
+
|
311
|
+
<td class="align-middle p-0"><a href="project-show.html"><img class="mr-3" data-src="holder.js/80x60?theme=noimage" width="80" height="60" alt=" [80x60]" style="width: 80px; height: 60px;" >Component</a></td>
|
312
|
+
|
313
|
+
</tr>
|
314
|
+
|
315
|
+
<tr>
|
316
|
+
|
317
|
+
<td class="align-middle p-0"><a href="project-show.html"><img class="mr-3" data-src="holder.js/80x60?theme=noimage" width="80" height="60" alt=" [80x60]" style="width: 80px; height: 60px;" >Component</a></td>
|
318
|
+
|
319
|
+
</tr>
|
320
|
+
|
321
|
+
</tbody>
|
322
|
+
|
323
|
+
</table>
|
324
|
+
|
325
|
+
</div>
|
326
|
+
|
327
|
+
</div>
|
328
|
+
|
329
|
+
<div class="col-6" ></div>
|
330
|
+
|
331
|
+
</div>
|
332
|
+
|
333
|
+
</div>
|
334
|
+
|
335
|
+
<div class="col-3" ></div>
|
336
|
+
|
337
|
+
</div>
|
338
|
+
|
339
|
+
<div class="row" >
|
340
|
+
|
341
|
+
<div class="col-12" >
|
342
|
+
|
343
|
+
<footer >
|
344
|
+
|
345
|
+
<div class="row">
|
346
|
+
|
347
|
+
<div class="col-sm-6">
|
348
|
+
|
349
|
+
<div class="card">
|
350
|
+
|
351
|
+
<div class="card-body">
|
352
|
+
|
353
|
+
<h5 class="card-title">Special title treatment</h5>
|
354
|
+
|
355
|
+
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
|
356
|
+
|
357
|
+
<a href="#" class="btn btn-primary">Go somewhere</a>
|
358
|
+
|
359
|
+
</div>
|
360
|
+
|
361
|
+
</div>
|
362
|
+
|
363
|
+
</div>
|
364
|
+
|
365
|
+
<div class="col-sm-6">
|
366
|
+
|
367
|
+
<div class="card">
|
368
|
+
|
369
|
+
<div class="card-body">
|
370
|
+
|
371
|
+
<h5 class="card-title">Special title treatment</h5>
|
372
|
+
|
373
|
+
<p class="card-text">With supporting text below as a natural lead-in to additional content.</p>
|
374
|
+
|
375
|
+
<a href="#" class="btn btn-primary">Go somewhere</a>
|
376
|
+
|
377
|
+
</div>
|
378
|
+
|
379
|
+
</div>
|
380
|
+
|
381
|
+
</div>
|
382
|
+
|
383
|
+
</div>
|
384
|
+
|
385
|
+
</footer>
|
386
|
+
|
387
|
+
</div>
|
388
|
+
|
389
|
+
</div>
|
390
|
+
|
391
|
+
</div>
|
392
|
+
|
393
|
+
<script src="./insidednd.js"></script>
|
394
|
+
|
395
|
+
</body>
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
</html>
|
400
|
+
|
401
|
+
```
|
1
テキストからリンクへ変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,4 +56,4 @@
|
|
56
56
|
|
57
57
|
## 試したこと
|
58
58
|
|
59
|
-
https://jsfiddle.net/juubee/6v3xfd76/
|
59
|
+
[自分の実装jsfiddle https://jsfiddle.net/juubee/6v3xfd76/](https://jsfiddle.net/juubee/6v3xfd76/)
|