Darken - A javascript library that makes darkmode easy

栏目: IT技术 · 发布时间: 6年前

内容简介:Just use this snippet to include darken to your code:

darken

:new_moon: Darkmode made easy

Table of Contents

Getting Started

:airplane: Using the CDN

Just use this snippet to include darken to your code:

<script src="https://unpkg.com/darken"></script>
<script>
	const darkmode = new darken();
</script>

:package: Using NPM

Install darken with npm:

npm install darken

And import it in your code:

import darken from 'darken';

const darkmode = new darken();

Usage

Basic

Here is a basic usage of darken:

<!-- index.html -->

<button id="darkmode-button">Toggle darkmode</button>

<script src="path/to/darken"></script>
<script>
	const darkmode = new darken({
		class: "darkmode-active",
		variables: {
			"--primary-color" : ["#000000", "#fafafa"],
			"--background-color" : ["#fafafa", "#000000"]
		},
		toggle: "#darkmode-button",
	});
</script>

You can either use a class and/or CSS variables to customize your styles.

Options

const defaultOptions = {
	container: null,
	default: "light",
	toggle: null,
	class: "darken",
	variables: {},
}

container

Type: String , Default: null

Element selector to the container of darken. The darkmode will be applied only to the selected container.

If the value is left to ``null`, the document element will be selected instead.

default

Type: String , Default: "light"

Defines the default mode on page load.

toggle

Type: String , Default: null

Element selector to the toggle button, the selected element will call the toggle method on click.

class

Type: String , Default: "darken"

Class that will be added to the selected container when the darkmode is active. The class is removed of the selected container once the darkmode is disabled.

If no container is selected, the class will be added to the body element instead.

variables

Type: Object , Default: {}

List of CSS variables that will change when the darkmode is active.

The keys of the object are the variables names, the value are arrays where the 1th index is the value the variable will take in lightmode and the 2nd index the value the variable will take in darkmode.

variables: {
	"--name-of-the-variable": ["lightmode value", "darkmode value"],
	"--background-color": ["white", "black"],
}

API

The darken class is the entry point to the library.

const darkmode = new darken(options);

toggle()

Return: none

Toggles darkmode.

darkmode.toggle();

on()

Return: none

Enables darkmode.

darkmode.on();

off()

Return: none

Disables darkmode.

darkmode.off();

Contributing

Any help and contribution is always welcome, feel free to submit issues and/or contribute to the project.

  1. Fork the Project
  2. Create your Feature or Fix Branch ( git checkout -b feature/feature-name or git checkout -b fix/fix-name )
  3. Commit your Changes ( git commit -m 'Add some feature or fix' )
  4. Push to the Branch ( git push origin feature/feature-name or git push origin fix/fix-name )
  5. Open a Pull Request

License

darken is distributed under the MIT License. See LICENSE for more information.

Contact

Colin Espinas - Website - contact@colinespinas.com

Project link: https://github.com/ColinEspinas/darken

Acknowledgements


以上所述就是小编给大家介绍的《Darken - A javascript library that makes darkmode easy》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

火的礼物:人类与计算技术的终极博弈(第4版)

火的礼物:人类与计算技术的终极博弈(第4版)

【美】Baase,Sara(莎拉芭氏) / 郭耀、李琦 / 电子工业出版社 / 89.00

《火的礼物:人类与计算技术的终极博弈 (第4版)》是一本讲解与计算技术相关的社会、法律和伦理问题的综合性读物。《火的礼物:人类与计算技术的终极博弈 (第4版)》以希腊神话中普罗米修斯送给人类的火的礼物作为类比,针对当前IT技术与互联网迅速发展带来的一些社会问题,从法律和道德的角度详细分析了计算机技术对隐私权、言论自由、知识产权与著作权、网络犯罪等方面带来的新的挑战和应对措施,讲解了计算技术对人类的......一起来看看 《火的礼物:人类与计算技术的终极博弈(第4版)》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码