HTML and CSS Reference
In-Depth Information
// Remove the drop effect from the target element
e.target.classList.remove('drop');
// See if the piece needs to be promoted
kingMe(newPiece);
}
}
function dragEnd(e) {
e.target.classList.remove("selected");
}
function dragEnter(e) {
// Get the img element that is being dragged
var dragID = e.dataTransfer.getData("text/plain");
var dragPiece = document.getElementById(dragID);
if (dragPiece &&
e.target.tagName === "DIV" &&
isValidMove(dragPiece, e.target, false)) {
e.target.classList.add('drop');
}
}
function dragLeave(e) {
e.target.classList.remove("drop");
}
function isValidMove(source, target, drop) {
// Get the piece prefix and location
var startPos = source.id.substr(1, 2);
var prefix = source.id.substr(0, 1);
// Get the drop location
var endPos = target.id;
// You can't drop on the existing location
if (startPos === endPos) {
return false;
}
// You can't drop on occupied square
if (target.childElementCount != 0) {
return false;
}
var jumpOnly = false;
if (source.classList.contains("jumpOnly")) {
jumpOnly = true;
}
Search WWH ::




Custom Search