Get knob to move when slider moves

This commit is contained in:
lolabird 2023-11-11 16:26:33 -07:00
commit 3c72666c70

View file

@ -56,7 +56,29 @@ function resetGrid() {
}
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);
const degrees = angle * (180 / Math.PI);
const sliderValue = Math.round((degrees / 360) * (rangeKnob.max - rangeKnob.min) + parseFloat(rangeKnob.min));
rangeKnob.style.transform = `rotate(${angle}deg)`;
rangeKnob.value = sliderValue;
}
function getGridDimensions() {
const min = gridSlider.min;
const max = gridSlider.max;
const value = gridSlider.value;
const percentage = ((value - min) / (max - min)) * 100;
rangeKnob.style.transform = `rotate(${percentage}deg)`;
numGrid = gridSlider.value;
while (container.firstChild) {
@ -98,18 +120,6 @@ 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");