Skip some code if the computer is slow

后端 未结 6 933
旧时难觅i
旧时难觅i 2021-02-04 09:27

Is there any way to detect if a computer is slow and not run some code (by either turning jQuery animations off or just running a function if it is fast)?

I kno

6条回答
  •  广开言路
    2021-02-04 09:38

    I'm guessing that the code which you want to switch off takes a significant amount of time to run.

    I suggest that you:

    • Begin to execute this code
    • After it's partially executed, see how much real-time has ellapsed
    • If too much real-time has ellapsed (i.e. if the code is executing too slowly) then cancel execution instead of finishing it.

提交回复
热议问题