Skip some code if the computer is slow

后端 未结 6 925
旧时难觅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:31

    Given that JavaScript runs in a partial trust environment, you're not going to be able to get any OS-level info, I would think.

    The best you can do really is test "responsiveness". A possible approach would be just to start playing the full animation and detect lag by comparing the target frame rate with "real" frame rate. You could then simply skip bits of the animation (code) to reduce the computation time and thus improve the responsiveness/frame-rate accordingly. This is essentially how many desktop games detect lag and thus reduce the complexity of animations. I can't guarantee it will work equally well in the browser with JavaScript, but it's worth a try certainly.

提交回复
热议问题