up
This commit is contained in:
parent
4272b7bb13
commit
508969c13f
168 changed files with 340 additions and 10 deletions
28
2-ui/1-document/11-coordinates/2-position-at/solution.view/index.css
Executable file
28
2-ui/1-document/11-coordinates/2-position-at/solution.view/index.css
Executable file
|
@ -0,0 +1,28 @@
|
|||
.note {
|
||||
position: fixed;
|
||||
z-index: 1000;
|
||||
padding: 5px;
|
||||
border: 1px solid black;
|
||||
background: white;
|
||||
text-align: center;
|
||||
font: italic 14px Georgia;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
background: #f9f9f9;
|
||||
border-left: 10px solid #ccc;
|
||||
margin: 0 0 0 100px;
|
||||
padding: .5em 10px;
|
||||
quotes: "\201C""\201D""\2018""\2019";
|
||||
display: inline-block;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
blockquote:before {
|
||||
color: #ccc;
|
||||
content: open-quote;
|
||||
font-size: 4em;
|
||||
line-height: .1em;
|
||||
margin-right: .25em;
|
||||
vertical-align: -.4em;
|
||||
}
|
82
2-ui/1-document/11-coordinates/2-position-at/solution.view/index.html
Executable file
82
2-ui/1-document/11-coordinates/2-position-at/solution.view/index.html
Executable file
|
@ -0,0 +1,82 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="index.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<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
|
||||
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.
|
||||
</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
|
||||
esse sequi officia sapiente.</p>
|
||||
|
||||
|
||||
<script>
|
||||
/**
|
||||
* Positions elem relative to anchor as said in position.
|
||||
*
|
||||
* @param {Node} anchor Anchor element for positioning
|
||||
* @param {string} position One of: top/right/bottom
|
||||
* @param {Node} elem Element to position
|
||||
*
|
||||
* Both elements: elem and anchor must be in the document
|
||||
*/
|
||||
function positionAt(anchor, position, elem) {
|
||||
|
||||
let anchorCoords = anchor.getBoundingClientRect();
|
||||
|
||||
switch (position) {
|
||||
case "top":
|
||||
elem.style.left = anchorCoords.left + "px";
|
||||
elem.style.top = anchorCoords.top - elem.offsetHeight + "px";
|
||||
break;
|
||||
|
||||
case "right":
|
||||
elem.style.left = anchorCoords.left + anchor.offsetWidth + "px";
|
||||
elem.style.top = anchorCoords.top + "px";
|
||||
break;
|
||||
|
||||
case "bottom":
|
||||
elem.style.left = anchorCoords.left + "px";
|
||||
elem.style.top = anchorCoords.top + anchor.offsetHeight + "px";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a note with the given html at the given position
|
||||
* relative to the anchor element.
|
||||
*/
|
||||
function showNote(anchor, position, html) {
|
||||
|
||||
let note = document.createElement('div');
|
||||
note.className = "note";
|
||||
note.innerHTML = html;
|
||||
document.body.append(note);
|
||||
|
||||
positionAt(anchor, position, note);
|
||||
}
|
||||
|
||||
// test it
|
||||
let blockquote = document.querySelector('blockquote');
|
||||
|
||||
showNote(blockquote, "top", "note above");
|
||||
showNote(blockquote, "right", "note at the right");
|
||||
showNote(blockquote, "bottom", "note below");
|
||||
</script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue