Skip to content

Commit e7c51e2

Browse files
committed
часть 3
1 parent 0157530 commit e7c51e2

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,42 +151,42 @@ setTimeout(() => message.remove(), 5000);
151151
152152
Чтобы изменить это, нам нужно использовать другую систему координат, где сообщение позиционировалось бы относительно документа, и свойство `position:absolute`.
153153
154-
## Координаты в контексте документа
154+
## Координаты относительно документа
155155
156-
Document-relative coordinates start from the upper-left corner of the document, not the window.
156+
В такой системе координат отсчёт ведётся от левого верхнего угла документа, не окна.
157157
158-
In CSS, window coordinates correspond to `position:fixed`, while document coordinates are similar to `position:absolute` on top.
158+
В CSS координаты относительно окна браузера соответствуют свойству `position:fixed`, а координаты относительно документа -- свойству `position:absolute` на самом верхнем уровне вложенности.
159159
160-
We can use `position:absolute` and `top/left` to put something at a certain place of the document, so that it remains there during a page scroll. But we need the right coordinates first.
160+
Мы можем воспользоваться свойствами `position:absolute` и `top/left`, чтобы привязать что-нибудь к конкретному месту в документе. При этом прокрутка страницы не имеет значения. Но сначала нужно получить верные координаты.
161161
162-
For clarity we'll call window coordinates `(clientX,clientY)` and document coordinates `(pageX,pageY)`.
162+
Для ясности обозначим координаты в контексте окна как `(clientX,clientY)` и в контексте документа как `(pageX,pageY)`.
163163
164-
When the page is not scrolled, then window coordinate and document coordinates are actually the same. Their zero points match too:
164+
Если страница не прокручена, то координаты в обеих системах совпадают, равно как и точка отсчёта:
165165
166166
![](document-window-coordinates-zero.png)
167167
168-
And if we scroll it, then `(clientX,clientY)` change, because they are relative to the window, but `(pageX,pageY)` remain the same.
168+
Но при прокрутке значения `(clientX,clientY)` меняются, потому что они привязаны к окну браузера, а `(pageX,pageY)` остаются такими же.
169169
170-
Here's the same page after the vertical scroll:
170+
Вот та же самая страница после вертикальной прокрутки:
171171
172172
![](document-window-coordinates-scroll.png)
173173
174-
- `clientY` of the header `"From today's featured article"` became `0`, because the element is now on window top.
175-
- `clientX` didn't change, as we didn't scroll horizontally.
176-
- `pageX` and `pageY` coordinates of the element are still the same, because they are relative to the document.
174+
- значение `clientY` заголовка `"From today's featured article"` стало равным `0`, потому что верхний край элемента достиг верхней границы окна.
175+
- значение `clientX` не поменялось, так как не было горизонтальной прокрутки.
176+
- значения координат `pageX` и `pageY` тоже не изменились, потому что они берутся относительно документа.
177177
178-
## Getting document coordinates [#getCoords]
178+
## Получаем координаты в контексте документа [#getCoords]
179179
180-
There's no standard method to get the document coordinates of an element. But it's easy to write it.
180+
Не существует стандартного метода, который возвращал бы координаты элемента относительно документа, но мы можем написать его сами.
181181
182-
The two coordinate systems are connected by the formula:
183-
- `pageY` = `clientY` + height of the scrolled-out vertical part of the document.
184-
- `pageX` = `clientX` + width of the scrolled-out horizontal part of the document.
182+
Две системы координат связаны следующими формулами:
183+
- `pageY` = `clientY` + высота вертикально прокрученной части документа.
184+
- `pageX` = `clientX` + ширина горизонтально прокрученной части документа.
185185
186-
The function `getCoords(elem)` will take window coordinates from `elem.getBoundingClientRect()` and add the current scroll to them:
186+
Функция `getCoords(elem)` берёт коордианты в контексте окна с помощью `elem.getBoundingClientRect()` и добавляет к ним значение соответствующей прокрутки:
187187
188188
```js
189-
// get document coordinates of the element
189+
// получаем координаты элемента в контексте документа
190190
function getCoords(elem) {
191191
let box = elem.getBoundingClientRect();
192192

0 commit comments

Comments
 (0)