-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslide-v1.js
68 lines (66 loc) · 2.37 KB
/
slide-v1.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
64
65
66
67
68
const slide = (function() {
let up = (target, duration = 500) => {
target.style.transitionProperty = "height, margin, padding";
target.style.transitionDuration = duration + "ms";
target.style.boxSizing = "border-box";
target.style.height = target.offsetHeight + "px";
target.offsetHeight;
target.style.overflow = "hidden";
target.style.height = 0;
target.style.paddingTop = 0;
target.style.paddingBottom = 0;
target.style.marginTop = 0;
target.style.marginBottom = 0;
window.setTimeout(() => {
target.style.display = "none";
target.style.removeProperty("height");
target.style.removeProperty("padding-top");
target.style.removeProperty("padding-bottom");
target.style.removeProperty("margin-top");
target.style.removeProperty("margin-bottom");
target.style.removeProperty("overflow");
target.style.removeProperty("transition-duration");
target.style.removeProperty("transition-property");
}, duration);
};
let down = (target, duration = 500) => {
target.style.removeProperty("display");
let display = window.getComputedStyle(target).display;
if (display === "none") display = "block";
target.style.display = display;
let height = target.offsetHeight;
target.style.overflow = "hidden";
target.style.height = 0;
target.style.paddingTop = 0;
target.style.paddingBottom = 0;
target.style.marginTop = 0;
target.style.marginBottom = 0;
target.offsetHeight;
target.style.boxSizing = "border-box";
target.style.transitionProperty = "height, margin, padding";
target.style.transitionDuration = duration + "ms";
target.style.height = height + "px";
target.style.removeProperty("padding-top");
target.style.removeProperty("padding-bottom");
target.style.removeProperty("margin-top");
target.style.removeProperty("margin-bottom");
window.setTimeout(() => {
target.style.removeProperty("height");
target.style.removeProperty("overflow");
target.style.removeProperty("transition-duration");
target.style.removeProperty("transition-property");
}, duration);
};
let toggle = (target, duration = 500) => {
if (window.getComputedStyle(target).display === "none") {
return down(target, duration);
} else {
return up(target, duration);
}
};
return {
up,
down,
toggle
};
})();