You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+27-4Lines changed: 27 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -200,6 +200,8 @@ const darkmode = new Darkmode(options)
200
200
201
201
### Basic
202
202
203
+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/basic/index.html)
204
+
203
205
Render the darkmode toggle with all the default options.
204
206
205
207
Import [drkmd.js](https://github.com/BetaHuhn/drkmd.js) like this:
@@ -236,6 +238,8 @@ Then specify the styles for the light and dark theme:
236
238
237
239
### CSS variables
238
240
241
+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/css-variables/index.html)
242
+
239
243
If you want to specify different colors for each theme, you can use [css-variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties):
240
244
241
245
**CSS**
@@ -263,6 +267,8 @@ body {
263
267
264
268
### With options
265
269
270
+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/options/index.html)
271
+
266
272
Render the darkmode toggle with custom options:
267
273
268
274
**HTML**
@@ -289,6 +295,8 @@ new Darkmode(options).attach()
289
295
290
296
### Custom darkmode toggle
291
297
298
+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/custom-toggle/index.html)
299
+
292
300
Don't render the darkmode toggle, instead change the theme when a custom HTML element is clicked.
293
301
294
302
Import [drkmd.js](https://github.com/BetaHuhn/drkmd.js) like this:
@@ -321,6 +329,8 @@ There's also `data-drkmd-to-light` and `data-drkmd-to-dark` which will change th
321
329
322
330
### Different images depending on the theme
323
331
332
+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/events/index.html)
333
+
324
334
You can use the `theme-change`[event](#events) to modify an element with JavaScript. Here we are changing the `src` attribute of an `img` tag when the theme changes:
325
335
326
336
**HTML**
@@ -347,6 +357,8 @@ window.addEventListener('theme-change', e => {
347
357
348
358
### Programmatic usage
349
359
360
+
[View example file](https://github.com/BetaHuhn/drkmd.js/blob/master/examples/programmatic/index.html)
361
+
350
362
You can also control the theme programmatically.
351
363
352
364
Import [drkmd.js](https://github.com/BetaHuhn/drkmd.js) like this:
@@ -365,18 +377,29 @@ or
365
377
importDarkmodefrom'drkmd-js'
366
378
```
367
379
380
+
Add HTML elements:
381
+
382
+
```html
383
+
<buttonid="myBtn">Click me</button>
384
+
<spanid="theme">Current theme:</span>
385
+
```
386
+
368
387
Then create a new Darkmode instance and use any of the available methods:
0 commit comments