Skip to content
Advertisement

How can I disable my click/drag selection box after one use?

I was wondering if anyone could help provide some input as to how I could disable the mousedown function after one instance of its use. The way I want it to work is so that it only works when enabled = true, and I change its value throughout the code in order to make it false by the end of the iteration of the functions. But for some reason despite it being false now it continues to be active. I was wondering if there is something I’m missing or if my approach to it is wrong. Any input would be a massive help.

Here is my code:

JavaScript

Advertisement

Answer

After a lot of trial and error I found out a solution to the problem. I created another function with the sole purpose of stopping the execution of mousedown() titled stopWorking.

Here is the function:

JavaScript

}

The reason I had to set document.onmousedown = null, is because after it is set to mouseup it continues that way no regardless of if I change enabled to equal false, since it has already been activated. And I inserted it at the end of the mouseup function (it is the last function called within the sequence of creating the highlight box.) Here is the code for that:

JavaScript

The reason I had to set document.onmousedown = null, is because after it is set to mouseup it continues that way no regardless of if I change enabled to equal false, since it has already been activated. Hope this helps anyone else going forward with similar issues!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement