Skip to content

Commit 2b18776

Browse files
committed
minor
1 parent 5d549f5 commit 2b18776

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

2-ui/1-document/11-coordinates/article.md

+22
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,28 @@ function getCoords(elem) {
220220
}
221221
```
222222
223+
If in the example above we use it with `position:absolute`, that would work right.
224+
225+
The modified `createMessageUnder` function:
226+
227+
```js
228+
function createMessageUnder(elem, html) {
229+
let message = document.createElement('div');
230+
message.style.cssText = "*!*position:absolute*/!*; color: red";
231+
232+
let coords = *!*getCoords(elem);*/!*
233+
234+
message.style.left = coords.left + "px";
235+
message.style.top = coords.bottom + "px";
236+
237+
message.innerHTML = html;
238+
239+
return message;
240+
}
241+
```
242+
243+
You'll find other examples in the task.
244+
223245
## Summary
224246
225247
Any point on the page has coordinates:

2-ui/1-document/11-coordinates/head.html

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
<script>
22
document.addEventListener('DOMContentLoaded', function() {
33

4-
let elem = document.getElementById('coords-show-mark');
4+
let elem = document.getElementById('coords-show-mark');
55

6-
// no elem in ebook mode
7-
if (elem) {
8-
elem.onclick = function() {
6+
// no elem in ebook (pdf/epub) mode
7+
if (elem) {
8+
elem.onclick = function() {
99

10-
function createMessageUnder(elem, text) {
11-
let coords = elem.getBoundingClientRect();
12-
let message = document.createElement('div');
13-
message.style.cssText = "position:fixed; color: red";
10+
function createMessageUnder(elem, text) {
11+
let coords = elem.getBoundingClientRect();
12+
let message = document.createElement('div');
13+
message.style.cssText = "position:fixed; color: red";
1414

15-
message.style.left = coords.left + "px";
16-
message.style.top = coords.bottom + "px";
15+
message.style.left = coords.left + "px";
16+
message.style.top = coords.bottom + "px";
1717

18-
message.innerHTML = text;
18+
message.innerHTML = text;
1919

20-
return message;
21-
}
20+
return message;
21+
}
2222

23-
let message = createMessageUnder(elem, 'Hello, world!');
24-
document.body.append(message);
25-
setTimeout(() => message.remove(), 5000);
23+
let message = createMessageUnder(elem, 'Hello, world!');
24+
document.body.append(message);
25+
setTimeout(() => message.remove(), 5000);
26+
}
2627
}
27-
}
2828

2929
});
3030

0 commit comments

Comments
 (0)