1 pièce(s) jointe(s)
Glisser déposer et tableaux en HTML 5
J'aimerais remplacer la case d'un tableau complexe par un autre comme ci-dessous:
Pièce jointe 254793
J'ai fais le code du glisser/posé mais ça ne marche pas!:oops: Merci, pour votre aide! ;)
Code de la "tuile" (vraiment oui! :mouarf:) à déplacer :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <table border="1" cellpadding="5" onclick="tourner()" draggable="true" ondragstart="drag(event)"> // ici, j'ai copié ce qu'il fallait pour le glisser/poser 8O
<tr >
<th width="20%" id=1000></th>
<th width="40%" id=1001></th>
<th width="20%" id=1002></th>
</tr ><tr>
<th width="20%" height='25' id=1003></th>
<th width="40%" height='25' ></th>
<th width="20%" height='25' id=1004></th>
</tr ><tr>
<th width="20%" id=1005></th>
<th width="40%" id=1006></th>
<th width="20%" id=1007></th>
</tr ><tr>
</table> |
Le code du tableau receveur:
Code:
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
| function cell(v){
var c=new cellule;
var taille=document.getElementById('taille').value;
var th=taille*2+1;
var tr=taille*2+1;
var i=0;
var j=0;
var cpt=0;
var id=0;
for (i=0; i<tr; i++){
if(tr%3==0){c.s=c.s+"<tr class='white' ondrop='drop(event)' ondragover='allowDrop(event)'>";} // Ici est le glisser/poser...
for(j=0; j<th; j++){
if (pair(j)==0 && pair(i)==0){c.s=c.s+"<th width='60' height='80' onclick='clic("+id+")' id="+id+" class='white' ></th>";id++;}
else if (pair(j)==0){
cpt=cpt+1;
if (noir[j]==1){c.s=c.s+"<th width='60' bgcolor='black' id="+id+" class='black' ></th>";id++;}
else{c.s=c.s+"<th width='60' id="+id+" class='white' ></th>";id++;}
}
else{
cpt=cpt+1;
if (noir[j]==1){c.s=c.s+"<th bgcolor='black' id="+id+" class='black' ></th>";id++;}
else{c.s=c.s+"<th id="+id+" class='white'></th>";id++;}}}
c.s=c.s+"</tr><tr class='white'>";
}
if(v==1){document.getElementById("c").innerHTML=c.s+"</table>";}
else{charger();}
} |
Le code glisser/poser :calim2:
Code:
1 2 3 4 5 6 7 8 9
| function allowDrop(ev){ev.preventDefault();}
function drag(ev){
ev.dataTransfer.setData("text", ev.target.id);}
function drop(ev){
ev.preventDefault();
var data=ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));} |
Merci pour votre aide!8-)