Javascript 在表格中拖动系统
我已经创建了这个表。我想设置一个变量Winner(即它是黑色或红色)。如果是B,哪个变量将拖动P1B.png。如果是R,它将拖动P2R.png。这是我的桌子(我试图拖动,但没有成功。我使用w3school() 首先,我想能够拖动它们。第二,如果可能的话,我想做一个系统拖动(因为我会在那之后做)。如果一个变量(variable winner让我们称它为==到B,那么我想能够只拖动P1B.png),如果variable it==仅拖动P2R.png)。我尝试了很多次,但失败了,所以我的一次尝试就是这样Javascript 在表格中拖动系统,javascript,html,drag,Javascript,Html,Drag,我已经创建了这个表。我想设置一个变量Winner(即它是黑色或红色)。如果是B,哪个变量将拖动P1B.png。如果是R,它将拖动P2R.png。这是我的桌子(我试图拖动,但没有成功。我使用w3school() 首先,我想能够拖动它们。第二,如果可能的话,我想做一个系统拖动(因为我会在那之后做)。如果一个变量(variable winner让我们称它为==到B,那么我想能够只拖动P1B.png),如果variable it==仅拖动P2R.png)。我尝试了很多次,但失败了,所以我的一次尝试就是这
<p id="demo"></p>
<script>
var winner;
switch (winner == B || winner == R ) {
case 0:
winner = ;
break;
case 1:
winner = ";
break;
case 2:
winner = "something went wrong";
}
document.getElementById("demo").innerHTML = "Player is playing now " + winner;
</script>
var赢家;
开关(winner==B | | winner==R){
案例0:
获胜者=;
打破
案例1:
winner=“;
打破
案例2:
winner=“出了问题”;
}
document.getElementById(“demo”).innerHTML=“玩家正在玩”+赢家;
//Make the DIV element draggagle:
dragElement(document.getElementById("dragme"));
function dragElement(elmnt) {
var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
if (document.getElementById(elmnt.id + "header")) {
/* if present, the header is where you move the DIV from:*/
document.getElementById(elmnt.id + "header").onmousedown = dragMouseDown;
} else {
/* otherwise, move the DIV from anywhere inside the DIV:*/
elmnt.onmousedown = dragMouseDown;
}
function dragMouseDown(e) {
e = e || window.event;
e.preventDefault();
// get the mouse cursor position at startup:
pos3 = e.clientX;
pos4 = e.clientY;
document.onmouseup = closeDragElement;
// call a function whenever the cursor moves:
document.onmousemove = elementDrag;
}
function elementDrag(e) {
e = e || window.event;
e.preventDefault();
// calculate the new cursor position:
pos1 = pos3 - e.clientX;
pos2 = pos4 - e.clientY;
pos3 = e.clientX;
pos4 = e.clientY;
// set the element's new position:
elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
}
function closeDragElement() {
/* stop moving when mouse button is released:*/
document.onmouseup = null;
document.onmousemove = null;
}
}
<p id="demo"></p>
<script>
var winner;
switch (winner == B || winner == R ) {
case 0:
winner = ;
break;
case 1:
winner = ";
break;
case 2:
winner = "something went wrong";
}
document.getElementById("demo").innerHTML = "Player is playing now " + winner;
</script>