-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo.html
More file actions
executable file
·157 lines (140 loc) · 4.83 KB
/
demo.html
File metadata and controls
executable file
·157 lines (140 loc) · 4.83 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>position-element Demo</title>
<style>
#anchor-red {
background-color: red;
width: 100px;
height: 100px;
position: absolute;
left: 300px;
top: 100px;
color: white;
}
#anchor-green {
background-color: green;
width: 100px;
height: 100px;
position: absolute;
left: 30px;
top: 100px;
color: white;
}
#subject {
background-color: blue;
width: 50px;
height: 50px;
left: -100px;
}
.container {
widht: 400px;
height: 300px;
text-align: center;
position: relative;
background-color: #f0f0f0;
}
label {
display: inline-block;
margin-left: 10px;
margin-right: 3px;
min-width: 90px;
cursor: pointer;
}
</style>
<script src="lib/position-element.js"></script>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script>
function update() {
var placement = $("input[name='placement']:checked").val();
var anchor = $("input[name='anchor']:checked").val();
var distance = $("#distance").val();
var offset = $("#offset").val();
var autoReposition = $("#autoReposition").prop('checked');
var config = {
element: document.getElementById('subject'),
anchorElement: document.getElementById(anchor),
preferredPlacement: placement,
distance: parseInt(distance, 10),
alignmentOffset: parseInt(offset, 10),
autoReposition: !!autoReposition,
};
var positionElement = window['position-element'].default;
positionElement(config);
}
$(function () {
$('input[type=radio][name=placement]').change(update);
$('input[type=radio][name=anchor]').change(update);
$('#distance').change(update);
$('#offset').change(update);
$('#autoReposition').change(update);
update();
});
</script>
</head>
<body>
<h1>position-element DEMO</h1>
<div class="container">
<div id="anchor-red">Anchor Red</div>
<div id="anchor-green">Anchor green</div>
<div id="subject"></div>
</div>
<h3>Select anchor element</h3>
<input name="anchor" type="radio" checked value='anchor-red' id="anchor-red-input" /><label
for="anchor-red-input">anchor-red</label>
<input name="anchor" type="radio" value='anchor-green' id="anchor-green-input" /><label
for="anchor-green-input">anchor-green</label>
<h3>Select placement</h3>
<p>
<input name="placement" type="radio" value='up-center' id="up-center" /><label for="up-center">up-center</label>
<input name="placement" type="radio" value='up-right' id="up-right" /><label for="up-right">up-right</label>
<input name="placement" type="radio" value='down-left' id="down-left" /><label for="down-left">down-left</label>
<input name="placement" type="radio" value='down-center' id="down-center" /><label
for="down-center">down-center</label>
<input name="placement" type="radio" value='up-left' id="up-left" /><label
for="up-left">up-left</label>
<input name="placement" type="radio" value='down-right' id="down-right" /><label for="down-right">down-right</label>
</p>
<p>
<input name="placement" type="radio" value='left-top' id="left-top" /><label for="left-top">left-top</label>
<input name="placement" type="radio" value='left-middle' id="left-middle" /><label
for="left-middle">left-middle</label>
<input name="placement" type="radio" value='left-bottom' id="left-bottom" /><label
for="left-bottom">left-bottom</label>
<input name="placement" type="radio" value='right-top' id="right-top" /><label for="right-top">right-top</label>
<input name="placement" type="radio" checked value='right-middle' id="right-middle" /><label
for="right-middle">right-middle</label>
<input name="placement" type="radio" value='right-bottom' id="right-bottom" /><label
for="right-bottom">right-bottom</label>
</p>
<p>
<input name="placement" type="radio" value='unknown' id="unknown" /><label for="unknown">unknown/not
set</label>
</p>
<h3>toggle auto reposition</h3>
<input id="autoReposition" type="checkbox" checked />
<label for="autoReposition">autoReposition</label>
( reposition when element goes out of viewport )
<h3>Adjust distance and offset</h3>
<label for="distance">Distance</label> <input id="distance" type="number" value="10" step="10">
<br />
<br />
<label for="offset">Alignment Offset</label> <input id="offset" type="number" value="0" step="2">
<h3>Code Example</h3>
<pre>
var config = {
element: document.getElementById('subject'),
anchorElement: document.getElementById('anchor'),
preferredPlacement: 'down-center',
distance: 10,
alignmentOffset: 0,
autoReposition: true,
};
positionElement(config);
</pre>
</body>
</html>