-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
63 lines (56 loc) · 1.44 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const controles = document.getElementById('controles');
const cssText = document.querySelector('.css');
const btn = document.querySelector('.btn');
controles.addEventListener('change', handleChange);
const handleStyle = {
element: btn,
backgroundColor(value) {
this.element.style.backgroundColor = value;
},
height(value) {
this.element.style.height = value + 'px';
},
width(value) {
this.element.style.width = value + 'px';
},
texto(value) {
this.element.innerText = value;
},
color(value) {
this.element.style.color = value;
},
border(value) {
this.element.style.border = value;
},
borderRadius(value) {
this.element.style.borderRadius = value + 'px';
},
fontFamily(value) {
this.element.style.fontFamily = value;
},
fontSize(value) {
this.element.style.fontSize = value + 'rem';
},
}
function handleChange(event) {
const name = event.target.name;
const value = event.target.value;
handleStyle[name](value);
saveValues(name, value);
showCss();
}
function saveValues(name, value) {
localStorage[name] = value;
}
function setValues() {
const properties = Object.keys(localStorage);
properties.forEach(propertie => {
handleStyle[propertie](localStorage[propertie]);
controles.elements[propertie].value = localStorage[propertie];
});
showCss();
}
setValues();
function showCss() {
cssText.innerHTML = '<span>' + btn.style.cssText.split('; ').join(';</span><span>');
}