From 2e5617e122539d076ca324a0f5594263099089b3 Mon Sep 17 00:00:00 2001 From: lolabird Date: Sat, 11 Nov 2023 15:09:20 -0700 Subject: [PATCH] Add knob --- index.html | 4 ++-- script.js | 38 ++++++++++++++++++++++++++++++++------ style.css | 8 ++++---- 3 files changed, 38 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index f9c108d..6208254 100644 --- a/index.html +++ b/index.html @@ -40,8 +40,8 @@
-
-
+
+
diff --git a/script.js b/script.js index a34c6c0..690df2b 100644 --- a/script.js +++ b/script.js @@ -2,15 +2,16 @@ const container = document.querySelector(".container"); const conWidth = container.clientWidth; const grid = document.createElement("div"); const gridSlider = document.querySelector("#gridSlider"); +gridSlider.defaultValue = 16; +const sliderLabel = document.querySelector("#sliderLabel"); +let numGrid; const buttons = document.querySelectorAll(".pen"); const colorPicker = document.querySelector("#custom-color"); -const reset = document.querySelector("#reset"); -const backColorPicker = document.querySelector("#back-col-picker") let colorValue; -let numGrid; -let sliderLabel = document.querySelector("#sliderLabel"); -gridSlider.defaultValue = 16; - +const backColorPicker = document.querySelector("#back-col-picker"); +const reset = document.querySelector("#reset"); +const rangeKnob = document.querySelector("#range-knob"); +let isDragging; //the next few variables are set to be used to test if @@ -37,7 +38,20 @@ backColorPicker.addEventListener("input", pickBackground); reset.addEventListener("click", resetGrid); gridSlider.addEventListener("input", getGridDimensions); gridSlider.addEventListener("change", getGridDimensions); +rangeKnob.addEventListener("mousedown", (e) => { + isDragging = true; + if (isDragging) { + document.addEventListener("mousemove", rotateKnob); + } + + document.addEventListener("mouseup", () => { + isDragging = false; + document.removeEventListener("mousemove", rotateKnob); + }); + + console.log(isDragging); +}); function resetGrid() { gridSlider.value = gridSlider.defaultValue; @@ -92,6 +106,18 @@ function createGrid() { } +function rotateKnob(e) { + const knobBounds = rangeKnob.getBoundingClientRect(); + const knobCenter = { + x: knobBounds.left + knobBounds.width/2, + y: knobBounds.top + knobBounds.height/2 + }; + let angle = Math.atan2(e.pageX - knobCenter.x, - (e.pageY - knobCenter.y) )*(180 / Math.PI); + + rangeKnob.style.transform = `rotate(${angle}deg)`; +} + + function toggleGridView(gridItem) { if (gridItem.classList.contains("grid-on")){ gridItem.classList.remove("grid-on"); diff --git a/style.css b/style.css index 1a67864..a436099 100644 --- a/style.css +++ b/style.css @@ -61,9 +61,9 @@ button { align-items: center; } -.range-knob { - width: 50px; - height: 50px; +.knob { + width: 80px; + height: 80px; border-radius: 50%; border: 1px solid #111; cursor: pointer; @@ -71,7 +71,7 @@ button { box-shadow: 1px 2px 10px 1px #555; } -.range-knotch { +.knotch { width: 10px; height: 10px; border-radius: 50%;