Skip to content

Commit f9e418d

Browse files
committed
Docs: improve offsetParent ex
1 parent 44af92b commit f9e418d

File tree

3 files changed

+48
-34
lines changed

3 files changed

+48
-34
lines changed
Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1-
.container {
1+
2+
table,
3+
.target,
4+
.container,
5+
.box {
26
padding: var(--padding);
3-
margin: var(--margin) 0;
4-
border: 2px solid var(--standard-30);
5-
background: var(--standard-5);
7+
border: 2px solid var(--border-color);
8+
width: 100%;
9+
min-height: 150px;
10+
box-sizing: var(--box-sizing);
11+
font-size: 12px;
12+
font-family: monospace;
13+
}
14+
15+
.container {
616
position: relative;
7-
height: 150px;
817
}
918

1019
.box {
11-
padding: var(--padding);
12-
margin: var(--margin);
13-
border: 2px solid var(--blue-30);
14-
background: var(--blue-5);
15-
height: 100px;
20+
border-color: var(--blue-border-color);
21+
background: var(--blue-background-color);
22+
}
23+
24+
table {
25+
border-color: var(--red-border-color);
26+
background: var(--red-background-color);
1627
}
1728

1829
.target {
19-
position: fixed;
20-
top: 20px;
21-
left: 20px;
30+
position: static;
31+
top: 14px;
32+
left: 14px;
2233
padding: var(--padding);
23-
background: var(--green-10);
24-
border: 2px solid var(--green-30);
25-
font-size: 12px;
26-
font-family: monospace;
34+
border-color: var(--orange-border-color);
35+
background: var(--orange-background-color);
2736
}
2837

2938
ui-button {
@@ -39,6 +48,6 @@ ui-button {
3948
}
4049

4150
.highlight {
42-
outline: 3px solid var(--red-40);
51+
outline: 3px solid var(--red-border-color);
4352
outline-offset: -3px;
4453
}
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
<div class="container">
22
<div class="box">
3-
<div class="target">
4-
position: fixed
5-
<br>top: 20px
6-
</div>
3+
<table>
4+
<tr>
5+
<td>
6+
<div class="target">
7+
position: fixed
8+
<br>top: 20px
9+
</div>
10+
</td>
11+
</tr>
12+
</table>
713
</div>
814
</div>
915

10-
<ui-button class="toggle-transform">Toggle Transform</ui-button>
11-
<ui-button class="toggle-filter">Toggle Filter</ui-button>
12-
<ui-button class="find">Find Containing Parent</ui-button>
16+
<ui-button class="toggle position">Toggle Position</ui-button>
17+
<ui-button class="toggle filter">Toggle Filter</ui-button>
18+
<ui-button class="find">Find Offset Parent</ui-button>
1319

1420
<div class="log"></div>

docs/src/examples/query/dom-traversal/query-offsetparent/page.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ const log = (text) => $log.text(text);
1111
log(`Target offsetTop: ${$target.prop('offsetTop')}px`);
1212

1313
// Toggle transform on box
14-
$('.toggle-transform').on('click', () => {
15-
const currentTransform = $box.css('transform');
16-
if (currentTransform === 'none') {
17-
$box.css('transform', 'scale(1)');
18-
log('Box transform set to: scale(1) - Now box is the offset parent!');
14+
$('.toggle.position').on('click', () => {
15+
if ($target.computedStyle('position') === 'static') {
16+
$target.css('position', 'fixed');
17+
log('Target set to position: fixed');
1918
}
2019
else {
21-
$box.css('transform', 'none');
22-
log('Box transform set to: none');
20+
$target.css('position', 'static');
21+
log('Target set to position: static');
2322
}
2423

2524
// Show how offsetTop is now relative to different element
@@ -29,8 +28,8 @@ $('.toggle-transform').on('click', () => {
2928
});
3029

3130
// Toggle filter on box
32-
$('.toggle-filter').on('click', () => {
33-
const currentFilter = $box.css('filter');
31+
$('.toggle.filter').on('click', () => {
32+
const currentFilter = $box.computedStyle('filter');
3433
if (currentFilter === 'none') {
3534
$box.css('filter', 'brightness(1)');
3635
log('Box filter set to: brightness(1) - Now box is the offset parent!');

0 commit comments

Comments
 (0)