+ 1
stop and continue in javascript
how can i stop execution of my code with mouse events and play it again
9 Answers
+ 7
First of all, do not use loops to sleep the thread, it's a bad practise and blocks the execution of all javascript in all browser tabs!!
Second, your code is a bit unreadable which makes it hard to debug, try splitting your html/css/js into their respective sections.
You should try changing the "20" to "0" (countdown) with js instead of having another hidden html section and keeping all of your js organised (use only as many timing functions as needed), Plus, the solution i offered you is complete enough if applied well, i can't do the work for you.
Your code needs a big rewrite, try completing the tutorials and trying again, i definitely can't make this work as you want it to /:
+ 8
Yes. You can do anything.
+ 7
Can you show me your code?
+ 5
Which part/lines you want to start/stop?
+ 5
Okay, the event you need is dbclick, put a stop case inside your interval, controlled by a global variable.
"dbclick" will set the "stop" variable from false to true and "click" will set it back to false.
setInterval(function interval() {
if (stop) return;
//code here
}, ...);
alldivs.ondbclick = () => stop = true;
alldivs.onclick = () => stop = false;
//implement that and tell me if it doesn't work as it should.
+ 1
@valen.h how i can do it ???
+ 1
+ 1
@valen.h if the user doublclick on any div stop toggle and wait for click to run again.
+ 1
@valen.h i did not understund please this is my code do it please
https://code.sololearn.com/Wm53vDCQ49UR/#html