Search code examples
javascriptgoogle-chrome-devtoolssetintervalthrottlingmobile-devices

setInterval(function(), 5) not working on iOS or any mobile device


So when I use my code in the browser, all works fine without any issue. However when I click on Chrome Dev Tools and use the device mode to simulate any type of mobile or ipad, and the code just does not run.

I have physically tried it on several new mobile devices also, and it still does not work. Even when I use the most simplest of code inside the function or reduce the interval values rate to next to nothing.. just no response.

It is linked to a button being pressed with the mouse / touch

function moveLeft() {
  time = setInterval(function () {
    angle += 1;
    if (angle > 360) {
      angle = 0;
    }
  }, 5);
}

I am guessing maybe there is some form of throttling going on that is stopping the processing from running quick enough, but even when i reduce the range it still does not work. The compatibility says it runs on all phones?


Solution

  • Okay, so it turns out this was a simple oversight from myself and was not actually related to setInterval.. I was trying to trigger a button hold using mousedown and mouseup event listeners.. obviously mobile devices use touchstart and touchend event listeners instead.. the setInterval feature does infact work perfectly fine and this explains why it was working everywhere except on mobile devices.