Skip to content

Commit

Permalink
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.
30 changes: 30 additions & 0 deletions week-3/color-picker.html
@@ -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>

0 comments on commit 82c2a73

Please sign in to comment.