"Styled <input type="range"> made to redirect not working on touch devices"
Bootstrap 4.1.1 Snippet by muhittinbudak

1
2
3
4
5
6
7
8
9
10
11
12
13
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div id="slide-wrap">
<div id="over">
<div id="overin"></div>
</div>
<input type="range" id="in" class="slideToUnlock" value="0" max="100">
</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
body {
color:white;
background: #323232;
margin:0;
padding:0;
}
#over {
width:80%;
border:solid thick rgba(255, 255, 255, 0.5);
margin:0 auto;
padding:0;
height:55px;
display:block;
position:relative;
background:rgba(255, 255, 255, 0.75);
border-bottom-left-radius:1em;
border-top-right-radius:1em;
}
#overin {
appearance:none;
-webkit-appearance:none;
-moz-appearance:none;
background:#60a917;
width:75px;
height:55px;
display:block;
border-bottom-left-radius:1em;
border-top-right-radius:1em;
}
#in {
outline:none;
-moz-appearance:none;
-webkit-appearance:none;
appearance:none;
width:80%;
margin:0 auto;
margin-top:-55px;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
var el = document.getElementById('in');
//mouse events
//gave names to the functions bound this, since w'll be using them two times.
el.onmousemove = enlarge;
el.onmouseup = redirect;
//touch events
//check if device has touch screen
// CREDIT : http://stackoverflow.com/a/4819886/1217785
if (is_touch_device()) {
console.log(true);
//onmousemove = touchmove
el.addEventListener("touchmove", enlarge, false)
//onmouseup = touchend
el.addEventListener("touchend", redirect, false)
}
//this function checks whether the device is a touch screen or not, else no binding will be done.
function is_touch_device() {
var isTouch = 'ontouchstart' in window ||
'onmsgesturechange' in window;
console.log(isTouch);
return isTouch;
};
//the rest of your functions
function redirect() {
var val = document.getElementById('in').value;
if (val >= 50) {
window.location.href = "http://www.example.com/";
} else {
this.value = 0;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: