-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
204 lines (170 loc) · 6.56 KB
/
index.html
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html>
<html>
<head>
<title>Arc Scrubber</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
html, body {
margin: 0;
padding: 0;
background-color: #000;
height: 100%;
width: 100%;
}
body {
overflow-x: hidden;
margin: 0 auto;
}
.container {
position: relative;
top: 70vh;
overflow: hidden;
height: 20vh;
}
.circle-container {
height: 7.5vw;
overflow: hidden;
position: relative;
width: 100vw;
margin: 5vh auto;
}
#circle {
height: 300vw;
width: 300vw;
border: 2px solid rgba(255,255,255,0.5);
border-radius: 50%;
margin: 0 auto;
box-sizing: border-box;
position: absolute;
z-index: 0;
left: -100vw;
}
#box {
width: calc(300vw / 2);
height: 15vw;
box-sizing: border-box;
position: absolute;
top: 0;
right: 0;
left: -25vw;
margin: 0 auto;
z-index: 1;
}
#dot {
height: 1.5625vw;
width: 1.5625vw;
background-color: white;
border-radius: 0;
position: absolute;
bottom: 0;
left: 0;
cursor: -webkit-grab;
cursor: -moz-grab;
cursor: -ms-grab;
cursor: -o-grab;
cursor: grab;
-webkit-tap-highlight-color: rgba(0,0,0,0);
}
#dot:active {
cursor: -webkit-grabbing;
cursor: -moz-grabbing;
cursor: -ms-grabbing;
cursor: -o-grabbing;
cursor: grabbing;
}
@media all and (max-width: 1000px) {
#dot {
height: 40px;
width: 40px;
}
#dot:active {
background-color: rgba(255,255,255,.7);
}
}
.text {
color: white;
font-family: 'Helvetica Neue';
font-weight: 100;
letter-spacing: .5px;
text-align: center;
position: absolute;
left: 0;
right: 0;
margin: 0 auto;
bottom: 0;
}
</style>
</head>
<body>
<a href="https://github.com/shiplet/arcscrubber"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/52760788cde945287fbb584134c4cbc2bc36f904/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f77686974655f6666666666662e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png"></a>
<div class="container">
<p class="text">Drag the dot!</p>
<div class="circle-container">
<div id="circle">
</div>
</div>
<div id="box">
<div id="dot"></div>
</div>
</div>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function(){
var circle = window.circle = document.getElementById('circle')
var dot = window.dot = document.getElementById('dot')
var box = window.box = document.getElementById('box')
var dragging = false
// Create reference points for circle
var left, top, diameter, radius, center, boxTop
var mosPosX, dotPosY, dotPosX
// Create dotPos limiters
var minY, minX, maxX
calcView()
createListeners()
/*
Core formula:
dotPosY = ((boxHeight - (circleTop - boxTop)) - (circleRadius - Math.sqrt(circleRadius^2 - mosPosX^2))) - dotHalfWidth
>> dotPosY must be negative if using translate3d()
>> dotHalfWidth is to center the dot on the circle bounds
>> (circleTop - boxTop) is for any desired upper offset between top of box and top of circle
*/
function activateDot() { dragging = true }
function deactivateDot() { dragging = false }
function shouldDotMove(event) { if(dragging) { dotPos(event) } }
function shouldScroll(event) { if(dragging){ event.preventDefault() } }
function calcView(event) {
left = circle.offsetLeft + circle.clientLeft
top = circle.getBoundingClientRect().top - document.body.getBoundingClientRect().top
boxTop = box.getBoundingClientRect().top - document.body.getBoundingClientRect().top
diameter = circle.offsetWidth
radius = diameter / 2
center = (left + (left + diameter)) / 2
minY = box.offsetWidth / 2
minX = -(dot.offsetWidth/2)
maxX = box.offsetWidth - (dot.offsetWidth/2)
dotPos(null, 0)
}
function dotPos(event, mosPos) {
event = event || {}
event = 'changedTouches' in event ? event.changedTouches[0] : event
event.clientX = mosPos === 0 ? window.innerWidth / 2 : event.clientX
mosPosX = event.clientX - center
dotPosY = -( ( (box.offsetHeight - (top - boxTop)) - ( radius - Math.sqrt( Math.pow( radius,2 ) - Math.pow( Math.min( Math.abs( mosPosX ), minY ), 2 ) ) ) ) - ( dot.offsetWidth/2 ) )
dotPosX = (event.clientX - left) - ((box.offsetWidth/2) + (dot.offsetWidth/2))
if(dotPosX <= minX) { dotPosX = minX }
if(dotPosX >= maxX) { dotPosX = maxX }
dot.style.transform = 'translate3d('+dotPosX+'px, '+dotPosY+'px, 0) rotate3d(0,0,1,45deg)'
}
function createListeners() {
window.addEventListener('resize', calcView)
window.addEventListener('touchmove', shouldScroll)
box.addEventListener('mousemove', shouldDotMove)
box.addEventListener('touchmove', shouldDotMove)
dot.addEventListener('mousedown', activateDot)
dot.addEventListener('touchstart', activateDot)
document.addEventListener('mouseup', deactivateDot)
document.addEventListener('touchend', deactivateDot)
}
}, false)
</script>
</body>
</html>