As I was updating my code, I realized that I needed to temporarily disable the "change" function. So, I introduced a variable called "enabled" and made the functions accessible only if var enabled == true
. At the end of the functions, I set enabled = false;
in order to disable the change();
function after its first execution. However, it seems like the function is still working perfectly. Can someone assist me with this issue?
//This function retrieves the ID of the images for conditional purposes
var enabled = true;
function getId(obj){
var correctId = obj.getAttribute('id');
return correctId;
}
if(enabled == true){
function drag(obj){
var zIndexImg = 0;
var id = obj.getAttribute('id');
var img = document.getElementById(id);
var imgPositionLeft = img.offsetLeft;
var imgPositionTop = img.offsetTop;
img.ondragstart = function(){
return false;
};
function dropImage(e){
// Dragging functionality
}
function change(id1,id2,div1,div2){
// Image swapping logic
}
function drop(e){
// Dropping image logic
}
// Event listeners for dragging
img.addEventListener('mousedown', function(){
document.addEventListener('mousemove', dropImage);
document.addEventListener('mouseup', drop);
});
}
enabled = false;
}