-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
47 lines (47 loc) · 1.48 KB
/
main.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
"use strict";
// https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Values_and_Units
if ("registerProperty" in CSS) {
//@ts-ignore
CSS.registerProperty({
name: "--circle-color",
syntax: "<color>",
initialValue: "black",
inherits: true,
});
//@ts-ignore
CSS.registerProperty({
name: "--circle-radius",
syntax: "<number>",
initialValue: "100",
inherits: true,
});
//@ts-ignore
CSS.registerProperty({
name: "--circle-amount",
syntax: "<integer>",
initialValue: "1",
inherits: true,
});
}
if ("paintWorklet" in CSS) {
//@ts-ignore
CSS.paintWorklet.addModule("worklet.js");
console.log("Sucess loading worklet");
}
else {
console.log("Browser doesn't support CSS Paint API");
}
const amountCircles = document.getElementById("amount");
const radiusCircles = document.getElementById("radius");
const colorCircles = document.getElementById("color");
const canvasPatterns = document.getElementById("pattern");
amountCircles.addEventListener("change", (e) => {
return canvasPatterns.style.setProperty("--circle-amount", e.target.value);
});
radiusCircles.addEventListener("change", (e) => {
return canvasPatterns.style.setProperty("--circle-radius", e.target.value);
});
colorCircles.addEventListener("change", (e) => {
return canvasPatterns.style.setProperty("--circle-color", e.target.value);
});
//https://css-tricks.com/updating-a-css-variable-with-javascript/