This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (33 loc) · 1.51 KB
/
index.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
const box = document.getElementById('box');
const horizontal = document.getElementById('horizontal');
const vertical = document.getElementById('vertical');
const blur = document.getElementById('blur');
const spread = document.getElementById('spread');
const color = document.getElementById('color');
const opacity = document.getElementById('opacity');
const codeOutput = document.getElementById('code-output');
function generateShadow() {
const horizontalValue = horizontal.value;
const verticalValue = vertical.value;
const blurValue = blur.value;
const spreadValue = spread.value;
const colorValue = color.value;
const opacityValue = opacity.value;
const rgba = hexToRGBA(colorValue, opacityValue);
const shadowValue = `${horizontalValue}px ${verticalValue}px ${blurValue}px ${spreadValue}px ${rgba}`;
box.style.boxShadow = shadowValue;
codeOutput.textContent = `box-shadow: ${shadowValue}`;
}
function hexToRGBA(hex, opacity) {
const r = parseInt(hex.slice(1, 3), 16);
const g = parseInt(hex.slice(3, 5), 16);
const b = parseInt(hex.slice(5, 7), 16);
return `rgba(${r}, ${g}, ${b}, ${opacity / 100})`;
}
horizontal.addEventListener('input', generateShadow);
vertical.addEventListener('input', generateShadow);
blur.addEventListener('input', generateShadow);
spread.addEventListener('input', generateShadow);
color.addEventListener('input', generateShadow);
opacity.addEventListener('input', generateShadow);
generateShadow();