npm 中文文档 npm 中文文档
指南
npmjs.com (opens new window)
指南
npmjs.com (opens new window)
  • 快速入门

    • npm 是什么?
    • npm 安装和更新
    • npm 防止权限错误
    • npm package.json 文件
    • npm 安装包
    • npm 更新包
    • npm 卸载包
    • npm 创建 Node.js 模块
    • npm 发布和更新包
    • npm 使用语义化版本
    • npm 使用 Dist-tags 标记包
    • npm 包和模块的了解
  • 命令行
  • 配置 npm

NoSleep.js


Prevent display sleep and enable wake lock in all Android and iOS web browsers.

Check out the live demo in any Android or iOS web browser.

Installation


This library is available on Bower as nosleep.

bower install nosleep

This package is published to npm as nosleep.jsand can be installed with:

npm install nosleep.js

Alternatively, you can manually add NoSleep.js to your project (or the minified version ).

Build from source


Install all development dependencies with:

npm install

To build this library run:

npm run build

A new build of NoSleep.js and NoSleep.min.js will now be available in the /dist directory.

Usage


Import ES6 module:

  1. ``` js
  2. import NoSleep from 'nosleep.js';
  3. ```

Create a new NoSleep object and then enable or disable it when needed.

To create a new NoSleep object:

  1. ``` js
  2. var noSleep = new NoSleep();
  3. ```

To enable wake lock:

NOTE: This function call must be wrapped in a user input event handler e.g. a mouse or touch handler

  1. ``` js
  2. // Enable wake lock.
  3. // (must be wrapped in a user input event handler e.g. a mouse or touch handler)
  4. document.addEventListener('click', function enableNoSleep() {
  5.   document.removeEventListener('click', enableNoSleep, false);
  6.   noSleep.enable();
  7. }, false);
  8. ```

To disable wake lock:

  1. ``` js
  2. // Disable wake lock at some point in the future.
  3. // (does not need to be wrapped in any user input event handler)
  4. noSleep.disable();
  5. ```

See example/index.html (and the live demo ) for more information.

Feedback


If you find any bugs or issues please report them on the NoSleep.js Issue Tracker.

If you would like to contribute to this project please consider forking this repo, making your changes and then creating a new Pull Request back to the main code repository.

License


MIT. Copyright (c) Rich Tibbett.

See the LICENSE file.
Last Updated: 2023-05-15 10:22:02