0
function move_img(){
  if(paused){

     paused = false;
     timerId = setInterval(() => disImg(), 800);

      if (miser.requestFullscreen) {
        miser.requestFullscreen();
      } else if (miser.mozRequestFullScreen) { /* Firefox */
        miser.mozRequestFullScreen();
      } else if (miser.webkitRequestFullscreen) { /* Chrome, Safari & Opera */
        miser.webkitRequestFullscreen();
      } else if (miser.msRequestFullscreen) { /* IE/Edge */
        miser.msRequestFullscreen();
      }

  }else{
    paused = true;
    clearInterval(timerId); // stop the clock
  }
}

I tried to stop the interval when exit from fullscreen. But I couldn't make it.

machineghost
  • 33,529
  • 30
  • 159
  • 234
smdmoz
  • 17
  • 3

1 Answers1

1

How to detect when a page exits fullscreen? is very similar to this. I'd recommend that you follow the top answer there, and listen for a fullscreenchange event, rather than use an interval to detect exits from full screens.

But if you did want to do an interval, you use of the code to clear it:

timerId = setInterval(() => disImg(), 800);

clearInterval(timerId); // stop the clock

is correct. However, I'd recommend not using global varibles, ie.:

const timerId = setInterval(() => disImg(), 800);

But the point is, you are clearing the interval correctly, so if disImg is still being called it's either coming from somewhere else, or your clearInterval isn't being reached.

If that's the case, I'd recommend adding console.log lines to try and debug why it isn't.

machineghost
  • 33,529
  • 30
  • 159
  • 234
  • I couldn't explain it.The thing that I want to do is : it is stopping in normal way .and I click the button it is starting to move when I exit from fullscreen with ESC it continues I want to stop when exit fullscreen.I hope I could express myself :) – smdmoz Jun 04 '20 at 23:15
  • Honestly I'm unclear, in a technical sense, what you are trying to accomplish. All I can say is that if you want to use intervals you have the right idea, but I'd recommend the event handling approach instead. The rest is up to your specific "stop" code, whatever it is. – machineghost Jun 04 '20 at 23:51