Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Outer corners
# Cantos externos

Outer corners are basically what we get from [elem.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect).
Os cantos externos são basicamente o que obtemos de [elem.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/DOM/element.getBoundingClientRect).

Coordinates of the upper-left corner `answer1` and the bottom-right corner `answer2`:
Coordenadas do canto superior esquerdo `answer1` e do canto inferior direito `answer2`:

```js
let coords = elem.getBoundingClientRect();
Expand All @@ -11,19 +11,19 @@ let answer1 = [coords.left, coords.top];
let answer2 = [coords.right, coords.bottom];
```

# Left-upper inner corner
# Canto interno superior esquerdo

That differs from the outer corner by the border width. A reliable way to get the distance is `clientLeft/clientTop`:
Esse difere do canto externo pela largura da borda. Uma forma confiável de obter a distância é `clientLeft/clientTop`:

```js
let answer3 = [coords.left + field.clientLeft, coords.top + field.clientTop];
```

# Right-bottom inner corner
# Canto interno inferior direito

In our case we need to substract the border size from the outer coordinates.
No nosso caso precisamos subtrair o tamanho da borda das coordenadas externas.

We could use CSS way:
Poderíamos usar a abordagem via CSS:

```js
let answer4 = [
Expand All @@ -32,7 +32,7 @@ let answer4 = [
];
```

An alternative way would be to add `clientWidth/clientHeight` to coordinates of the left-upper corner. That's probably even better:
Uma forma alternativa seria adicionar `clientWidth/clientHeight` às coordenadas do canto superior esquerdo. Isso é provavelmente ainda melhor:

```js
let answer4 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<meta charset="utf-8">
<link rel="stylesheet" href="index.css">
<script>
document.onclick = function(e) { // shows click coordinates
document.onclick = function(e) { // mostra as coordenadas do clique
coords.innerHTML = e.clientX + ':' + e.clientY;
};
</script>
</head>

<body>

Click anywhere to get window coordinates.
<br> That's for testing, to check the result you get by JavaScript.
Clique em qualquer lugar para obter as coordenadas da janela.
<br> Isso é para teste, para verificar o resultado que você obtém via JavaScript.
<br>
<div id="coords">(click coordinates show up here)</div>
<div id="coords">(as coordenadas do clique aparecem aqui)</div>


<div id="field">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
<meta charset="utf-8">
<link rel="stylesheet" href="index.css">
<script>
document.onclick = function(e) { // shows click coordinates
document.onclick = function(e) { // mostra as coordenadas do clique
coords.innerHTML = e.clientX + ':' + e.clientY;
};
</script>
</head>

<body>

Click anywhere to get window coordinates.
<br> That's for testing, to check the result you get by JavaScript.
Clique em qualquer lugar para obter as coordenadas da janela.
<br> Isso é para teste, para verificar o resultado que você obtém via JavaScript.
<br>
<div id="coords">(click coordinates show up here)</div>
<div id="coords">(as coordenadas do clique aparecem aqui)</div>


<div id="field">
Expand All @@ -32,7 +32,7 @@


<script>
// ...your code...
// ...seu código...
</script>

</body>
Expand Down
22 changes: 11 additions & 11 deletions 2-ui/1-document/11-coordinates/1-find-point-coordinates/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ importance: 5

---

# Find window coordinates of the field
# Encontre as coordenadas da janela do campo

In the iframe below you can see a document with the green "field".
No iframe abaixo você pode ver um documento com o "campo" verde.

Use JavaScript to find window coordinates of corners pointed by with arrows.
Use JavaScript para encontrar as coordenadas da janela dos cantos apontados pelas setas.

There's a small feature implemented in the document for convenience. A click at any place shows coordinates there.
Há um pequeno recurso implementado no documento para conveniência. Um clique em qualquer lugar mostra as coordenadas ali.

[iframe border=1 height=360 src="source" link edit]

Your code should use DOM to get window coordinates of:
Seu código deve usar o DOM para obter as coordenadas da janela de:

1. Upper-left, outer corner (that's simple).
2. Bottom-right, outer corner (simple too).
3. Upper-left, inner corner (a bit harder).
4. Bottom-right, inner corner (there are several ways, choose one).
1. Canto externo superior esquerdo (isso é simples).
2. Canto externo inferior direito (também simples).
3. Canto interno superior esquerdo (um pouco mais difícil).
4. Canto interno inferior direito (há várias formas, escolha uma).

The coordinates that you calculate should be the same as those returned by the mouse click.
As coordenadas que você calcular devem ser as mesmas retornadas pelo clique do mouse.

P.S. The code should also work if the element has another size or border, not bound to any fixed values.
P.S. O código também deve funcionar se o elemento tiver outro tamanho ou borda, sem ficar amarrado a nenhum valor fixo.
6 changes: 3 additions & 3 deletions 2-ui/1-document/11-coordinates/2-position-at/solution.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In this task we only need to accurately calculate the coordinates. See the code for details.
Nesta tarefa só precisamos calcular as coordenadas com precisão. Veja o código para os detalhes.

Please note: the elements must be in the document to read `offsetHeight` and other properties.
A hidden (`display:none`) or out of the document element has no size.
Note: os elementos precisam estar no documento para ler `offsetHeight` e outras propriedades.
Um elemento oculto (`display:none`) ou fora do documento não tem tamanho.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
esse sequi officia sapiente.</p>

<blockquote>
Teacher: Why are you late?
Student: There was a man who lost a hundred dollar bill.
Teacher: That's nice. Were you helping him look for it?
Student: No. I was standing on it.
Professor: Por que você está atrasado?
Aluno: Tinha um homem que perdeu uma nota de cem dólares.
Professor: Que legal. Você estava ajudando ele a procurar?
Aluno: Não. Eu estava em cima dela.
</blockquote>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit sint atque dolorum fuga ad incidunt voluptatum error fugiat animi amet! Odio temporibus nulla id unde quaerat dignissimos enim nisi rem provident molestias sit tempore omnis recusandae
Expand All @@ -24,13 +24,13 @@

<script>
/**
* Positions elem relative to anchor as said in position.
* Posiciona elem em relação a anchor, de acordo com position.
*
* @param {Node} anchor Anchor element for positioning
* @param {string} position One of: top/right/bottom
* @param {Node} elem Element to position
* @param {Node} anchor Elemento de referência para o posicionamento
* @param {string} position Um de: top/right/bottom
* @param {Node} elem Elemento a ser posicionado
*
* Both elements: elem and anchor must be in the document
* Ambos os elementos, elem e anchor, devem estar no documento
*/
function positionAt(anchor, position, elem) {

Expand All @@ -56,8 +56,8 @@
}

/**
* Shows a note with the given html at the given position
* relative to the anchor element.
* Mostra uma nota com o html dado na posição dada
* em relação ao elemento de referência.
*/
function showNote(anchor, position, html) {

Expand All @@ -69,12 +69,12 @@
positionAt(anchor, position, note);
}

// test it
// teste
let blockquote = document.querySelector('blockquote');

showNote(blockquote, "top", "note above");
showNote(blockquote, "right", "note at the right");
showNote(blockquote, "bottom", "note below");
showNote(blockquote, "top", "nota acima");
showNote(blockquote, "right", "nota à direita");
showNote(blockquote, "bottom", "nota abaixo");
</script>


Expand Down
32 changes: 16 additions & 16 deletions 2-ui/1-document/11-coordinates/2-position-at/source.view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
esse sequi officia sapiente.</p>

<blockquote>
Teacher: Why are you late?
Student: There was a man who lost a hundred dollar bill.
Teacher: That's nice. Were you helping him look for it?
Student: No. I was standing on it.
Professor: Por que você está atrasado?
Aluno: Tinha um homem que perdeu uma nota de cem dólares.
Professor: Que legal. Você estava ajudando ele a procurar?
Aluno: Não. Eu estava em cima dela.
</blockquote>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit sint atque dolorum fuga ad incidunt voluptatum error fugiat animi amet! Odio temporibus nulla id unde quaerat dignissimos enim nisi rem provident molestias sit tempore omnis recusandae
Expand All @@ -24,21 +24,21 @@

<script>
/**
* Positions elem relative to anchor as said in position.
* Posiciona elem em relação a anchor, de acordo com position.
*
* @param {Node} anchor Anchor element for positioning
* @param {string} position One of: top/right/bottom
* @param {Node} elem Element to position
* @param {Node} anchor Elemento de referência para o posicionamento
* @param {string} position Um de: top/right/bottom
* @param {Node} elem Elemento a ser posicionado
*
* Both elements: elem and anchor must be in the document
* Ambos os elementos, elem e anchor, devem estar no documento
*/
function positionAt(anchor, position, elem) {
// ... your code ...
// ... seu código ...
}

/**
* Shows a note with the given html at the given position
* relative to the anchor element.
* Mostra uma nota com o html dado na posição dada
* em relação ao elemento de referência.
*/
function showNote(anchor, position, html) {

Expand All @@ -50,12 +50,12 @@
positionAt(anchor, position, note);
}

// test it
// teste
let blockquote = document.querySelector('blockquote');

showNote(blockquote, "top", "note above");
showNote(blockquote, "right", "note at the right");
showNote(blockquote, "bottom", "note below");
showNote(blockquote, "top", "nota acima");
showNote(blockquote, "right", "nota à direita");
showNote(blockquote, "bottom", "nota abaixo");
</script>


Expand Down
16 changes: 8 additions & 8 deletions 2-ui/1-document/11-coordinates/2-position-at/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ importance: 5

---

# Show a note near the element
# Mostre uma nota perto do elemento

Create a function `positionAt(anchor, position, elem)` that positions `elem`, depending on `position` near `anchor` element.
Crie uma função `positionAt(anchor, position, elem)` que posiciona `elem`, dependendo de `position`, perto do elemento `anchor`.

The `position` must be a string with any one of 3 values:
- `"top"` - position `elem` right above `anchor`
- `"right"` - position `elem` immediately at the right of `anchor`
- `"bottom"` - position `elem` right below `anchor`
O `position` deve ser uma string com um dos 3 valores:
- `"top"` - posiciona `elem` logo acima de `anchor`
- `"right"` - posiciona `elem` imediatamente à direita de `anchor`
- `"bottom"` - posiciona `elem` logo abaixo de `anchor`

It's used inside function `showNote(anchor, position, html)`, provided in the task source code, that creates a "note" element with given `html` and shows it at the given `position` near the `anchor`.
Ela é usada dentro da função `showNote(anchor, position, html)`, fornecida no código fonte da tarefa, que cria um elemento de "nota" com o `html` dado e o mostra na `position` dada, perto do `anchor`.

Here's the demo of notes:
Aqui está a demonstração das notas:

[iframe src="solution" height="350" border="1" link]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The solution is actually pretty simple:
A solução, na verdade, é bem simples:

- Use `position:absolute` in CSS instead of `position:fixed` for `.note`.
- Use the function [getCoords()](info:coordinates#getCoords) from the chapter <info:coordinates> to get document-relative coordinates.
- Use `position:absolute` no CSS em vez de `position:fixed` para `.note`.
- Use a função [getCoords()](info:coordinates#getCoords) do capítulo <info:coordinates> para obter as coordenadas relativas ao documento.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
esse sequi officia sapiente.</p>

<blockquote>
Teacher: Why are you late?
Student: There was a man who lost a hundred dollar bill.
Teacher: That's nice. Were you helping him look for it?
Student: No. I was standing on it.
Professor: Por que você está atrasado?
Aluno: Tinha um homem que perdeu uma nota de cem dólares.
Professor: Que legal. Você estava ajudando ele a procurar?
Aluno: Não. Eu estava em cima dela.
</blockquote>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit sint atque dolorum fuga ad incidunt voluptatum error fugiat animi amet! Odio temporibus nulla id unde quaerat dignissimos enim nisi rem provident molestias sit tempore omnis recusandae
Expand Down Expand Up @@ -66,12 +66,12 @@
positionAt(anchor, position, note);
}

// test it
// teste
let blockquote = document.querySelector('blockquote');

showNote(blockquote, "top", "note above");
showNote(blockquote, "right", "note at the right");
showNote(blockquote, "bottom", "note below");
showNote(blockquote, "top", "nota acima");
showNote(blockquote, "right", "nota à direita");
showNote(blockquote, "bottom", "nota abaixo");
</script>


Expand Down
8 changes: 4 additions & 4 deletions 2-ui/1-document/11-coordinates/3-position-at-absolute/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ importance: 5

---

# Show a note near the element (absolute)
# Mostre uma nota perto do elemento (absolute)

Modify the solution of the [previous task](info:task/position-at) so that the note uses `position:absolute` instead of `position:fixed`.
Modifique a solução da [tarefa anterior](info:task/position-at) para que a nota use `position:absolute` em vez de `position:fixed`.

That will prevent its "runaway" from the element when the page scrolls.
Isso vai impedir que ela "escape" do elemento quando a página rolar.

Take the solution of that task as a starting point. To test the scroll, add the style `<body style="height: 2000px">`.
Use a solução daquela tarefa como ponto de partida. Para testar a rolagem, adicione o estilo `<body style="height: 2000px">`.
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
esse sequi officia sapiente.</p>

<blockquote>
Teacher: Why are you late?
Student: There was a man who lost a hundred dollar bill.
Teacher: That's nice. Were you helping him look for it?
Student: No. I was standing on it.
Professor: Por que você está atrasado?
Aluno: Tinha um homem que perdeu uma nota de cem dólares.
Professor: Que legal. Você estava ajudando ele a procurar?
Aluno: Não. Eu estava em cima dela.
</blockquote>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Reprehenderit sint atque dolorum fuga ad incidunt voluptatum error fugiat animi amet! Odio temporibus nulla id unde quaerat dignissimos enim nisi rem provident molestias sit tempore omnis recusandae
Expand Down Expand Up @@ -83,10 +83,10 @@

let blockquote = document.querySelector('blockquote');

showNote(blockquote, "top-in", "note top-in");
showNote(blockquote, "top-out", "note top-out");
showNote(blockquote, "right-out", "note right-out");
showNote(blockquote, "bottom-in", "note bottom-in");
showNote(blockquote, "top-in", "nota top-in");
showNote(blockquote, "top-out", "nota top-out");
showNote(blockquote, "right-out", "nota right-out");
showNote(blockquote, "bottom-in", "nota bottom-in");
</script>


Expand Down
Loading