Repository navigation
Expand file tree
/
Copy pathcss-gradient-generator.html
More file actions
65 lines (61 loc) · 2.08 KB
/
Copy pathcss-gradient-generator.html
File metadata and controls
65 lines (61 loc) · 2.08 KB
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
64
65
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CSS Gradient Generator</title>
<script type="application/masscode-tool+json">
{
"schemaVersion": 1,
"name": "CSS Gradient Generator",
"description": "Preview a two-color linear gradient and copy its CSS.",
"category": "design",
"author": "massCode",
"authorUrl": "https://github.com/massCodeIO",
"license": "MIT",
"keywords": ["css", "background", "color", "gradient"]
}
</script>
<style>
#preview { min-height: 10rem; border-radius: var(--radius, 8px); }
#css { min-width: 0; width: 100%; }
</style>
</head>
<body>
<h1>CSS Gradient Generator</h1>
<div class="mc-card mc-grid">
<div id="preview" role="img" aria-label="Gradient preview"></div>
<div class="mc-row">
<label>Start <input type="color" id="start" value="#1459dc"></label>
<label>End <input type="color" id="end" value="#4ce8b8"></label>
</div>
<label>Angle <output id="degrees" for="angle"></output>
<input type="range" id="angle" min="0" max="360" value="120">
</label>
<label>CSS <textarea id="css" rows="2" readonly></textarea></label>
<button type="button" id="copy" class="mc-btn-primary">Copy CSS</button>
<p id="status" class="mc-error" role="status"></p>
</div>
<script>
const get = id => document.getElementById(id)
function update() {
const degrees = `${get('angle').value}deg`
const gradient = `linear-gradient(${degrees}, ${get('start').value}, ${get('end').value})`
get('degrees').value = degrees
get('preview').style.backgroundImage = gradient
get('css').value = `background-image: ${gradient};`
}
for (const id of ['start', 'end', 'angle'])
get(id).addEventListener('input', update)
get('copy').addEventListener('click', async () => {
get('status').textContent = ''
try {
await window.massCode.copy(get('css').value)
}
catch {
get('status').textContent = 'The copy request could not be completed.'
}
})
update()
</script>
</body>
</html>