-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.js
63 lines (46 loc) · 1.18 KB
/
slider.js
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
var pos;
var gutter;
var gutterRect;
var handle;
var handleRect;
function init()
{
gutter = document.getElementById("slider_gutter");
gutterRect = gutter.getBoundingClientRect();
handle = document.getElementById("slider_handle");
handleRect = handle.getBoundingClientRect();
handle.addEventListener("mousedown", mousedown, false);
}
function mousedown(evt)
{
evt.preventDefault();
pos = handle.y.baseVal.value - evt.clientY;
document.addEventListener("mousemove", mousemove, true);
document.addEventListener("mouseup", mouseup, true);
}
function mouseup(evt)
{
evt.preventDefault();
document.removeEventListener("mousemove", mousemove, true);
document.removeEventListener("mouseup", mouseup, true);
}
function mousemove(evt)
{
evt.preventDefault();
var val = evt.clientY + pos;
changeVal(val);
}
function changeVal(value)
{
var sr = handle.ownerSVGElement.suspendRedraw(1000);
var maxY = gutterRect.height - handleRect.height;
var minY = 0.5;
if(value > maxY) {
value = maxY;
} else if (value < minY) {
value = minY;
}
handle.y.baseVal.value = value;
//console.log(Math.ceil(((value - 0.5) / maxY) * 100));
handle.ownerSVGElement.unsuspendRedraw(sr);
}