-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
144 lines (107 loc) · 5.7 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
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="jquery-ui.min.js"></script>
<style>
.slidify input[type=range] { display: none; }
.slidify { position: relative; list-style: none; margin: 0px; padding: 0px; }
.slidify li { z-index: 1; position: absolute !important; cursor: pointer; user-select: none; top: 0px; left: 0px; display: inline-block; }
.slidify li a { background: #abcdef; z-index: 10; position: relative; opacity: 0.1; color: #000; text-decoration: none; display: inline-block; white-space: nowrap; line-height: 40px; }
.slidify li a:hover { opacity: 0.8; }
.slidify li a:active,
.slidify li a:focus { z-index: 100; opacity: 1.0; }
#.slidify li a { left: -50%; }
.slider { width: 400px; height: 40px; outline: 1px solid #f0f; margin: 10px 100px; }
</style>
</head>
<body>
<ul id="slider1" name="circleStrafeRadius" class="slider"></ul>
<ul id="slider2" name="circleStrafeRadius" class="slider"></ul>
<script>
!function ($, undefined) {
var sliderCount = 0;
var drawTick = function(slidify)
{
var $range = $('input[type=range]', this);
$range.attr('max', slidify.options.max);
$range.val(this._data.value);
var offset = slidify.width() * (this._data.value - slidify.options.min) / (slidify.options.max - slidify.options.min) - this.width() / 2;
this.css({ 'left': offset + 'px' });
}
var drawSlider = function()
{
for (var i = 0, j = this.values.length; i < j; i++) {
drawTick.call(this.values[i], this);
}
}
var initialize = function(data, options)
{
options = options || {
min: 1,
max: 100,
};
return function() {
this.slidify = $(this);
if (this.slidify.values == null) {
this.slidify.values = [];
var elementName = this.slidify.attr('name') || ('slidify' + sliderCount);
sliderCount++;
this.slidify.empty();
var slidify = this.slidify;
for (var i = 0, j = data.length; i < j; i++) {
this.slidify.values[i] = $('<li><input type="range" name="' + elementName + '[' + i + ']" /><a href="#' + data[i].key + '">' + data[i].name + '</a></li>');
this.slidify.values[i]._data = {};
this.slidify.append(this.slidify.values[i]);
this.slidify.values[i].data('slidify', this.slidify.values[i]);
this.slidify.values[i].draggable({
axis: "x",
start: function(e, elem) { },
drag: function (e, elem) {
var $li = $(this).data('slidify');
var offset = $li.width() / 2;
var value = ((elem.position.left + offset) / slidify.options.width) *
(slidify.options.max - slidify.options.min) +
slidify.options.min;
var overflow = (value > slidify.options.max && elem.position.left > elem.originalPosition.left);
var underflow = (value < slidify.options.min && elem.position.left < elem.originalPosition.left);
value = Math.max(Math.min(Math.round(value, 0), slidify.options.max), slidify.options.min);
// console.log(value);
$li._data.value = Math.round(value, 0);
drawTick.call($li, slidify);
if (overflow) elem.position.left = slidify.options.width - offset;
if (underflow) elem.position.left = 0 - offset;
},
stop: function() {}
});
}
}
this.slidify.options = options;
this.slidify.options.width = this.slidify.options.width || this.slidify.width();
this.slidify.options.height = this.slidify.options.height || this.slidify.height();
for (var i = 0, j = data.length; i < j; i++) {
$.extend(this.slidify.values[i]._data, data[i]);
}
this.slidify.addClass('slidify');
drawSlider.call(this.slidify);
return this;
};
};
$.fn.slidify = function() {
switch (arguments.length)
{
case 0: return this.map(function() { return this.slidify; });
case 1:
case 2: return this.each(initialize(arguments[0], arguments[1]));
}
return this;
};
}(jQuery);
</script>
<script>
$('ul').slidify([{name:'M50 Interceptor', key:'ORIG_M50', value:10},{name:'F7C Hornet', key:'ANVL_F7C', value:100},{name:'Sabre', key:'AEGS_Sabre', value:20},{name:'350R', key:'ORIG_350R', value:45}], { min: 10, max: 100 });
$('#slider2').slidify([{name:'M50 Interceptor', key:'ORIG_M50', value:10},{name:'F7C Hornet', key:'ANVL_F7C', value:40},{name:'Sabre', key:'AEGS_Sabre', value:20},{name:'350R', key:'ORIG_350R', value:30}], { min: 10, max: 100 });
console.log($('#slider1').slidify());
</script>
</body>
</html>