Get knob to move when slider moves
This commit is contained in:
parent
32f58ce4d4
commit
3c72666c70
1 changed files with 22 additions and 12 deletions
34
script.js
34
script.js
|
|
@ -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() {
|
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;
|
numGrid = gridSlider.value;
|
||||||
|
|
||||||
while (container.firstChild) {
|
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) {
|
function toggleGridView(gridItem) {
|
||||||
if (gridItem.classList.contains("grid-on")){
|
if (gridItem.classList.contains("grid-on")){
|
||||||
gridItem.classList.remove("grid-on");
|
gridItem.classList.remove("grid-on");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue