-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.html
87 lines (75 loc) · 2.61 KB
/
slider.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<style>
* {
margin: 0;
padding: 0;
}
.container {
width: 300px;
height: 30px;
display: flex;
flex-flow: row nowrap;
}
.left,
.right {
height: 100%;
}
.left {
background: red;
}
.right {
background: blue;
}
.drag {
background: #eee;
}
</style>
<script src="https://cdn.bootcss.com/eruda/1.5.8/eruda.min.js"></script>
<script>
eruda.init();
</script>
</head>
<body>
<div class="container">
<div class="left">left</div>
<div class="drag">Drag</div>
<div class="right">right</div>
</div>
<!-- <script>
var dragDom = document.querySelector(".drag"),
left = document.querySelector(".left"),
right = document.querySelector(".right"),
container = document.querySelector(".container"),
mousedownX = 0,
lW = left.offsetWidth;
right.style.width = right.offsetWidth;
left.style.width = (num1 / (num2 + num1)) * 100 + "%";
right.style.width = (num2 / (num2 + num1)) * 100 + "%";
console.log(container.offsetWidth);
var mouseMoveHandler = function(e) {
var width = e.clientX - mousedownX;
var calcLW = lW + width;
calcLW < 0 ? (calcLW = 0) : 1;
calcLW > container.offsetWidth ? (calcLW = container.offsetWidth) : 0;
left.style.width = calcLW + "px";
right.style.width = container.offsetWidth - calcLW + "px";
console.log(left.style.width, right.style.width);
};
dragDom.addEventListener("mousedown", function(e) {
mousedownX = e.clientX;
lW = left.offsetWidth;
console.log(22222);
});
dragDom.addEventListener("mousemove", mouseMoveHandler);
dragDom.addEventListener("mouseup ", function() {
dragDom.removeEventListener("mousemove", mouseMoveHandler);
});
</script> -->
</body>
</html>