Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Color Picker added
- Loading branch information
tsbugbee
committed
Feb 9, 2020
1 parent
3fc8288
commit 82c2a73
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>Color picker</title> | ||
</head> | ||
<body> | ||
|
||
<form> | ||
<input type="color" name="bg" id="bg"> | ||
</form> | ||
|
||
<script> | ||
var picker = document.getElementById('bg'); | ||
var body = document.querySelector('body'); | ||
const keyName = 'colorSetting'; | ||
body.style.backgroundColor = localStorage.getItem(keyName); | ||
bg.value = localStorage.getItem(keyName); | ||
|
||
picker.addEventListener('change', function(event) { | ||
let hex = this.value; | ||
body.style.backgroundColor = hex; | ||
localStorage.setItem(keyName, hex); | ||
}); | ||
|
||
</script> | ||
</body> | ||
</html> |