Giter VIP home page Giter VIP logo

night.js's Introduction

NPM version NPM downloads

How to Install

At the beginning install the library in your project via npm or Yarn:

$ npm install night.js
$ yarn add night.js

Getting Started

Connect using script tag in HTML:

<script src="/directory/to/library/folder/night.js"></script>

Or CommonJS/ES6 import:

const Night = require('night.js'); // CommonJS
import Night from 'night.js'; // ES6

Next use library with:

โ€ข Vanilla JavaScript e.g:

const night = new Night({
  // options...
});

Functions

โ€ข Switch between light and dark mode:

night.toggle();

โ€ข Switch mode automatically (based on time, location and sun position):

night.auto();

โ€ข Reset localStorage data:

night.reset();

Options

Name Type Default Description Available options
lightClass string Class added to body when light mode is active Name of the class
darkClass string dark Class added to body when dark mode is active Name of the class
cache boolean true Cache location coordinates in local storage for one day true (enable), false (disable)
cacheClear boolean true Clear location coordinates in local storage everyday at midnight true (enable), false (disable)
auto boolean true Enable smart switch on script init true (enable), false (disable)
onAuto function null Callback on smart switch () => { // code }
onLight function null Callback when dark mode is disabled () => { // code }
onDark function null Callback when dark mode is enabled () => { // code }
onToggle function null Callback on dark/light mode toggle () => { // code }
onDenied function null Callback on geolocation permission denied () => { // code }
onCacheClear function null Callback when location coordinates and midnight time in local storage cleared () => { // code }
onReset function null Callback on localStorage reset () => { // code }

Events

smartDark event will output sun position times and user geolocation latitude & longitude

smartDarkError event will output message when permission to geolocation is denied

License

This project is licensed under the MIT License ยฉ 2018-present Jakub Biesiada

night.js's People

Contributors

dependabot[bot] avatar jb1905 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

night.js's Issues

Callbacks

  • onInit
  • onBrightness
  • onBrightnessNotSupported
  • onAccess
  • onAccessDenied
  • onSoundPlay
  • onSoundPause

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.