Skip some code if the computer is slow

后端 未结 6 937
旧时难觅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条回答
  •  猫巷女王i
    2021-02-04 09:30

    The most simple solution would be to leave it up to the user with a check box, but other wise you could try timing the first animation for a computer and then if it exceeds a certain time limit, the remaining animations are turned off... for example...

    var start = new Date();
    //... some jQuery animation
    var end = new Date();
    var diff = end - start;
    

    Then, for example, if the animation should take 1.5 seconds, and the time difference is like 5 seconds, then turn off any remaining animations.

提交回复
热议问题