-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwheel_html.html
More file actions
136 lines (122 loc) · 3.81 KB
/
wheel_html.html
File metadata and controls
136 lines (122 loc) · 3.81 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Wheel Slider</title>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
overflow: hidden;
}
.slider {
position: absolute;
width: 100%;
height: 100%;
top: 67.5%;
left: 50%;
transform: translate(-50%, -50%);
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 30px;
height: 30px;
background: #F44336;
cursor: pointer;
}
.slider::-moz-range-thumb {
width: 30px;
height: 30px;
background: #F44336;
cursor: pointer;
}
.slider::-ms-thumb {
width: 30px;
height: 30px;
background: #F44336;
cursor: pointer;
}
.wheel-container {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 600px;
height: 600px;
overflow: hidden; /* Ensure pointer overlaps */
}
.wheel {
position: relative;
width: 100%;
height: 100%;
border-radius: 50%;
background-image: url('wheel.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
cursor: grab;
}
.pointer {
position: absolute;
top: -5%; /* Overlap a bit over the top */
left: 50%;
transform: translateX(-50%);
width: 10%;
padding-top: 10%;
background-image: url('pointer.png');
background-size: contain;
background-position: center;
background-repeat: no-repeat;
z-index: 1;
}
</style>
</head>
<body>
<input type="range" min="0" max="360" value="180" class="slider" oninput="rotateWheel(this.value)">
<div class="wheel-container" id="wheelContainer">
<div class="wheel" id="wheel"></div>
<div class="pointer" id="pointer"></div>
</div>
<script>
const wheel = document.getElementById('wheel');
const wheelContainer = document.getElementById('wheelContainer');
const pointer = document.getElementById('pointer');
let isDragging = false;
let previousAngle = 0;
function rotateWheel(deg) {
wheel.style.transform = `rotate(${deg}deg)`;
}
function getAngle(event) {
const centerX = wheelContainer.offsetLeft + wheelContainer.offsetWidth / 2;
const centerY = wheelContainer.offsetTop + wheelContainer.offsetHeight / 2;
const deltaX = event.clientX - centerX;
const deltaY = event.clientY - centerY;
return Math.atan2(deltaY, deltaX) * (180 / Math.PI);
}
function startDrag(event) {
isDragging = true;
previousAngle = getAngle(event);
document.addEventListener('mousemove', drag);
document.addEventListener('mouseup', endDrag);
}
function drag(event) {
if (!isDragging) return;
const currentAngle = getAngle(event);
const deltaAngle = currentAngle - previousAngle;
const currentRotation = parseInt(wheel.style.transform.replace('rotate(', '').replace('deg)', ''));
const newRotation = (currentRotation + deltaAngle) % 360;
wheel.style.transform = `rotate(${newRotation}deg)`;
previousAngle = currentAngle;
}
function endDrag() {
isDragging = false;
document.removeEventListener('mousemove', drag);
document.removeEventListener('mouseup', endDrag);
}
wheel.addEventListener('mousedown', startDrag);
</script>
</body>
</html>