Skip to content

Commit

Permalink
finished color picker
Browse files Browse the repository at this point in the history
  • Loading branch information
bpd01001 committed Feb 10, 2020
1 parent 5fb14b0 commit 16e861d
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions week-3/color-picker.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,28 @@
<body>

<form >

<input type="color" name="bg" id="bg">
</form>


<script>
let picker = document.getElementById('bg');
let picker = document.querySelector('#bg');
let body = document.querySelector('body');
let keyName = "bgColor";
let bgColor = window.localStorage.getItem(keyName) || '#ffffff';


picker.addEventListener('change', function(event) {
let hex = this.value;
console.log(hex);
setBg(hex);
window.localStorage.setItem(keyName, hex);

})
body.style.backgroundColor = hex;
localStorage.setItem("myBgColor", hex);

});

function setBg(color){
body.style.backgroundColor = color;
picker.value = color;
}

setBg(bgColor);
// Get the current color
let bgColor = localStorage.getItem("myBgColor") || '#cccccc';
body.style.backgroundColor = bgColor;
picker.value = bgColor;


</script>
Expand Down

0 comments on commit 16e861d

Please sign in to comment.