From 074785cea106179cb3305637055ab0a009ca74f2 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:42:52 -0500 Subject: initial commit --- files/ru/web/api/window/screenx/index.html | 97 ++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 files/ru/web/api/window/screenx/index.html (limited to 'files/ru/web/api/window/screenx/index.html') diff --git a/files/ru/web/api/window/screenx/index.html b/files/ru/web/api/window/screenx/index.html new file mode 100644 index 0000000000..ad30bf1e30 --- /dev/null +++ b/files/ru/web/api/window/screenx/index.html @@ -0,0 +1,97 @@ +--- +title: Window.screenX +slug: Web/API/Window/screenX +tags: + - API + - Property + - Read-only + - Reference + - Window + - screenX +translation_of: Web/API/Window/screenX +--- +
{{APIRef}}
+ +

Свойство Window.screenX только для чтения возвращает горизонтальное расстояние в пикселях CSS левой границы окна просмотра браузера пользователя до левой части экрана.

+ +
+

Заметка: Псевдоним screenX был реализован во всех современных браузерах - {{domxref ("Window.screenLeft")}}. Первоначально это поддерживалось только в IE, но было введено повсеместно из-за популярности.

+
+ +

Синтаксис

+ +
leftWindowPos = window.screenX
+
+ +

Возвращает

+ +

Число, равное количеству пикселей CSS от левого края окна просмотра браузера до левого края экрана.

+ +

Пример

+ +

В нашем примере screenleft-screentop вы увидите холст, на котором нарисован круг. В этом примере мы используем {{domxref ("Window.screenLeft")}}/{{domxref ("Window.screenTop")}} плюс {{domxref("Window.requestAnimationFrame ()")}}, чтобы постоянно перерисовывать круг в том же физическом положении на экране, даже если позиция окна перемещается.

+ +
initialLeft = window.screenLeft + canvasElem.offsetLeft;
+initialTop = window.screenTop + canvasElem.offsetTop;
+
+function positionElem() {
+  let newLeft = window.screenLeft + canvasElem.offsetLeft;
+  let newTop = window.screenTop + canvasElem.offsetTop;
+
+  let leftUpdate = initialLeft - newLeft;
+  let topUpdate = initialTop - newTop;
+
+  ctx.fillStyle = 'rgb(0, 0, 0)';
+  ctx.fillRect(0, 0, width, height);
+  ctx.fillStyle = 'rgb(0, 0, 255)';
+  ctx.beginPath();
+  ctx.arc(leftUpdate + (width/2), topUpdate + (height/2) + 35, 50, degToRad(0), degToRad(360), false);
+  ctx.fill();
+
+  pElem.textContent = 'Window.screenLeft: ' + window.screenLeft + ', Window.screenTop: ' + window.screenTop;
+
+  window.requestAnimationFrame(positionElem);
+}
+
+window.requestAnimationFrame(positionElem);
+ +

Они работают точно так же, как screenX / screenY.

+ +

Также в код мы включили фрагмент, который определяет, поддерживается ли screenLeft, и, если нет, заполняет поли в screenLeft / screenTop, используя screenX / screenY.

+ +
if(!window.screenLeft) {
+  window.screenLeft = window.screenX;
+  window.screenTop = window.screenY;
+}
+ +

Спецификация

+ + + + + + + + + + + + + + + + +
СпецификацияСтатусКомментарий
{{ SpecName('CSSOM View', '#dom-window-screenx', 'Window.screenX') }}{{ Spec2('CSSOM View') }}Initial definition.
+ +

Совместимость браузера

+ + + +

{{Compat("api.Window.screenX")}}

+ +

Смотрите также

+ + -- cgit v1.2.3-54-g00ecf