hibernate状态
Web developers still have a difficult job when it comes to mobile; the web will never provide as many APIs or as much control as native mobile platforms but our users expect the same excellent experience. Creating HTML5 games and media-heavy apps for the web can be really difficult, as you really have to pay attention to performance the the rest of the little things that native platforms provide.
在移动领域,Web开发人员仍然面临艰巨的任务。 网络将永远不会提供与本机移动平台一样多的API或控件,但是我们的用户希望获得同样的出色体验。 在网络上创建HTML5游戏和需要大量媒体的应用程序可能非常困难,因为您必须真正关注本机平台提供的其余小功能的性能。
One of those small features includes preventing the device from sleeping when the user hasn't been active. Imagine your user playing a game that doesn't require much interaction, experiencing a VR demo, or even just a blog post or slideshow, and the screen suddenly goes black -- that's an annoyance that your users may not (and shouldn't have to) tolerate. That's where NoSleep.js comes in: a small Wake Lock API shim to prevent the browser and device from going to sleep!
这些小功能之一包括防止用户不活动时使设备进入Hibernate状态。 想象一下,您的用户在玩一个不需要太多交互的游戏,正在经历一个VR演示,甚至只是一个博客文章或幻灯片,而屏幕突然变黑了–这是您的用户可能不愿意的(并且不应该拥有容忍。 那就是NoSleep.js进来的地方:一个小的Wake Lock API垫片,以防止浏览器和设备进入睡眠状态!
Using NoSleep.js is super easy. To start the no sleep effect, simply add:
使用NoSleep.js非常简单。 要开始无睡眠效果,只需添加:
var noSleep = new NoSleep(); function enableNoSleep() { noSleep.enable(); document.removeEventListener('touchstart', enableNoSleep, false); } // Enable wake lock. // (must be wrapped in a user input event handler e.g. a mouse or touch handler) document.addEventListener('touchstart', enableNoSleep, false);Once you want to cede control of sleep, simply call the disable method:
一旦您想放弃对睡眠的控制,只需调用disable方法:
// Disable wake lock at some point in the future. // (does not need to be wrapped in any user input event handler) noSleep.disable();So how does NoSleep.js prevent the sleep effect? NoSleep.js mocks a tiny mp4 video and continuously plays it, which works because browsers know enough to not signal sleep when a video is playing. What a clever way to prevent the device from sleeping!
那么,NoSleep.js如何防止睡眠效果? NoSleep.js会模拟一个微小的mp4视频并连续播放,这是有效的,因为浏览器知道在播放视频时不会发出睡眠信号。 防止设备进入Hibernate状态的聪明方法!
Will we ever get a JavaScript API that allows us to control whether the device sleeps or not? Possibly -- no browser vendor has committed to the Wake Lock API yet. That's why us web developers have to stay clever and take matters into our own hands!
我们能否获得一个JavaScript API,该API可以控制设备是否睡眠? 可能-尚未有任何浏览器供应商承诺使用Wake Lock API。 这就是为什么我们的Web开发人员必须保持聪明,将事情掌握在自己手中!
翻译自: https://davidwalsh.name/wake-lock-shim
hibernate状态