I am studying CSS
and testing a simple drag and drop functionality which comes with HTML5
.
The page I have prepared looks OK in Chrome and Opera but totally wrong in Firefox and IE 11. In IE 11 it is even not possible to drag elements from the rightmost table onto a caption Table A nor Table B.
Why is it so? How is the height for td
element magically set to a high value in Firefox/IE and not in Chrome/Opera? Why does dropping not work in IE 11?
function drag(event) {
event.dataTransfer.setData("rowId", event.target.id);
}
function allowDrop(event) {
event.preventDefault();
}
function drop(event) {
event.preventDefault();
var playerId = event.dataTransfer.getData("rowId");
var tableBody = event.target.parentNode.getElementsByTagName("tbody");
if (tableBody) {
tableBody[0].appendChild(document.getElementById(playerId));
}
}
.vbtn {
background: none repeat scroll 0 0 #fafaff;
border: 1px solid #ddd;
border-radius: 6px;
border-spacing: 0;
box-shadow: 1px 1px 1px #eee;
padding: 1px 8px;
text-shadow: 0 2px 5px rgba(120, 120, 120, 0.3);
vertical-align: baseline;
white-space: nowrap;
}
a {
color: #175bb0;
text-decoration: none;
}
#wrapper {
width: 100%;
overflow: hidden;
}
#section-b {
position: relative;
margin-left: 10px;
width: 300px;
height: 400px;
float: left;
overflow: auto;
}
#section-a {
width: 235px;
float: left;
}
#selector {
margin-top: 10px;
margin-left: 10px;
float: left;
}
table {
margin-top: 10px;
margin-bottom: 10px;
margin-right: 10px;
width: 100%;
border: 1px solid black;
}
th,
td {
width: 100%;
border: none;
}
thead {
background: lightgreen;
}
thead>tr {
position: relative;
}
tbody {
height: 400px;
background: none;
overflow: auto;
}
<!DOCTYPE html>
<head>
<title>Table scroll</title>
<meta charset="UTF-8" />
</head>
<body>
<div id="wrapper">
<div id="header">
<p>Header...</p>
</div>
<div id="section-a">
<table id="table-a">
<caption ondrop="drop(event)" ondragover="allowDrop(event)">Table A</caption>
<thead>
<tr>
<th>Attribute 1</th>
<th>Attribute 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<table id="table-b">
<caption ondrop="drop(event)" ondragover="allowDrop(event)">Table B</caption>
<thead>
<tr>
<th>Attribute 1</th>
<th>Attribute 2</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div id="selector">
<select>
<optgroup label="A">
<option value="1">A</option>
<option value="2">B</option>
<option value="3">C</option>
<option value="4">D</option>
</optgroup>
<optgroup label="B">
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
<option value="d">d</option>
</optgroup>
</select>
</div>
<div id="section-b">
<table id="section-b-list">
<thead>
<tr>
<th>Attribute 1</th>
<th>Attribute 2</th>
</tr>
</thead>
<tbody>
<tr draggable="true" id="10" ondragstart="drag(event)">
<td><a href="#" class="vbtn" draggable="false">Value 1</a>
</td>
<td>Value 2</td>
</tr>
<tr draggable="true" id="11" ondragstart="drag(event)">
<td><a href="#" class="vbtn" draggable="false">Value 3</a>
</td>
<td>Value 4</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>