0

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?

Phil
  • 157,677
  • 23
  • 242
  • 245
Hakaewt
  • 49
  • 1
  • 7
  • 1
    How do you know it doesn't run? – Phil Jun 10 '20 at 00:46
  • @Phil I have arrow keys set up also that appear to be working so I think it must be something to do with mobile devices screwing with the way the function is actually being triggered in the first place.. answering a reply to you a second ago actually forced me into the realization of part of the potential answer in my head so I have deleted my reply and I will see if I can play with it as 'maybe' it is not the setInterval failing afterall – Hakaewt Jun 10 '20 at 00:56
  • Put `console.log("working")` in the function. Do you see the log messages? – Barmar Jun 10 '20 at 01:00
  • Perhaps related: https://stackoverflow.com/questions/9647215/what-is-minimum-millisecond-value-of-settimeout#:~:text=The%20minimum%20is%204ms%20(as,times%20are%20never%20100%25%20accurate.&text=setTimeout%20is%20most%20probably%20calling%20the%20sleep%20or%20Sleep%20system%20call. – Barmar Jun 10 '20 at 01:02

1 Answers1

0

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.

Hakaewt
  • 49
  • 1
  • 7