Skip to content

Commit 97777c5

Browse files
committed
Work on docs for intersects/isinview
1 parent 221d744 commit 97777c5

File tree

4 files changed

+92
-44
lines changed

4 files changed

+92
-44
lines changed

docs/src/examples/query/dimensions/query-intersects/page.css

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,26 @@
66
margin: 50px;
77
border-radius: var(--border-radius);
88
overflow: auto;
9+
10+
/* force scroll */
11+
.filler {
12+
width: 500px;
13+
height: 500px;
14+
}
915
}
1016

1117
.box {
1218
position: absolute;
1319
padding: 15px;
20+
text-align: center;
21+
align-content: center;
1422
border-radius: var(--border-radius);
1523
text-align: center;
1624
font-weight: bold;
1725
cursor: pointer;
1826
user-select: none;
27+
transition: var(--transition);
28+
transition-property: border, background;
1929

2030
&.source {
2131
width: 100px;
@@ -35,11 +45,25 @@
3545
background: var(--orange-background-color);
3646
border: var(--orange-border);
3747
color: var(--orange-text-color);
48+
49+
}
50+
51+
&.overlap {
52+
opacity: 0;
53+
background: var(--red-background-color);
54+
padding: 0px;
55+
border: var(--red-border);
56+
color: var(--red-text-color);
57+
z-index: 2;
58+
font-size: 7px;
59+
overflow: hidden;
60+
text-overflow: ellipsis;
61+
white-space: nowrap;
3862
}
3963

4064
&.intersecting {
4165
background: var(--green-background-color);
42-
border-color: var(--green-30);
66+
border-color: var(--green-border);
4367
color: var(--green-text-color);
4468
}
4569
}

docs/src/examples/query/dimensions/query-intersects/page.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<div class="container">
2+
<div class="target box">
3+
Target
4+
<div class="overlap box">Intersection</div>
5+
</div>
26
<div class="source box">Source</div>
3-
<div class="target box">Target</div>
7+
<div class="filler"></div>
48
</div>
59

610
<div class="output">
Lines changed: 60 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,12 @@
11
import { $ } from '@semantic-ui/query';
2-
3-
function checkIntersection() {
4-
const result = $('.source').intersects('.target', {
5-
returnDetails: true,
6-
});
7-
console.log(result);
8-
const info = `INTERSECTION DETAILS:
9-
10-
Intersects: ${result.intersects ? '✓ YES' : '✗ NO'}
11-
Overlap Ratio: ${(result.ratio * 100).toFixed(1)}%
12-
13-
Side Detection:
14-
Top: ${result.top ? '✓' : '✗'}
15-
Bottom: ${result.bottom ? '✓' : '✗'}
16-
Left: ${result.left ? '✓' : '✗'}
17-
Right: ${result.right ? '✓' : '✗'}
18-
19-
${
20-
result.rect
21-
? `Intersection Rectangle:
22-
X: ${result.rect.left.toFixed(1)}px
23-
Y: ${result.rect.top.toFixed(1)}px
24-
Width: ${result.rect.width.toFixed(1)}px
25-
Height: ${result.rect.height.toFixed(1)}px`
26-
: 'Intersection Rectangle: None'
27-
}`;
28-
29-
$('.output pre').text(info);
30-
31-
// Update visual state
32-
const $boxes = $('.box');
33-
if (result.intersects) {
34-
$boxes.addClass('intersecting');
35-
}
36-
else {
37-
$boxes.removeClass('intersecting');
38-
}
39-
}
2+
import { mapObject, roundNumber } from '@semantic-ui/utils';
403

414
// Drag functionality
425
let isDragging = false;
436
let $dragged = null;
447
let offset = { top: 0, left: 0 };
458

9+
// handle drag and drop start
4610
$('.box').on('mousedown', function(event) {
4711
event.preventDefault();
4812
isDragging = true;
@@ -55,6 +19,7 @@ $('.box').on('mousedown', function(event) {
5519
moveElementToMouse(event);
5620
});
5721

22+
// handle drag & drop
5823
$(document)
5924
.on('pointermove', function(event) {
6025
if (isDragging && $dragged) {
@@ -70,11 +35,66 @@ function moveElementToMouse(event) {
7035
const container = $('.container').dimensions();
7136
$dragged.position({
7237
relativeTo: '.container',
73-
top: event.clientY - container.top - offset.top,
74-
left: event.clientX - container.left - offset.left,
38+
top: event.clientY - container.top + container.scrollTop - offset.top,
39+
left: event.clientX - container.left + container.scrollLeft - offset.left,
7540
});
7641
checkIntersection();
7742
}
7843

7944
// Initial check
8045
checkIntersection();
46+
47+
function checkIntersection() {
48+
const result = $('.source').intersects('.target', {
49+
returnDetails: true,
50+
});
51+
const rect = (result.rect)
52+
? mapObject(result.rect, val => `${roundNumber(val)}px`)
53+
: null;
54+
const info = `INTERSECTION DETAILS:
55+
56+
Intersects: ${result.intersects ? '✓ YES' : '✗ NO'}
57+
Overlap Ratio: ${(result.ratio * 100).toFixed(1)}%
58+
59+
Side Detection:
60+
Top: ${result.top ? '✓' : '✗'}
61+
Bottom: ${result.bottom ? '✓' : '✗'}
62+
Left: ${result.left ? '✓' : '✗'}
63+
Right: ${result.right ? '✓' : '✗'}
64+
65+
${
66+
result.rect
67+
? `Intersection Rectangle:
68+
X: ${roundNumber(rect.left)}
69+
Y: ${roundNumber(rect.top)}
70+
Width: ${roundNumber(rect.width)}
71+
Height: ${roundNumber(rect.height)}`
72+
: 'Intersection Rectangle: None'
73+
}`;
74+
75+
$('.output pre').text(info);
76+
77+
if (rect) {
78+
$('.overlap').css({
79+
opacity: 1,
80+
top: rect.top,
81+
left: rect.left,
82+
width: rect.width,
83+
height: rect.height,
84+
});
85+
}
86+
else {
87+
$('.overlap').css({
88+
opacity: 0,
89+
});
90+
}
91+
92+
// Update visual state
93+
const $boxes = $('.box').not('.overlap');
94+
if (result.intersects) {
95+
$boxes.addClass('intersecting');
96+
}
97+
else {
98+
$boxes.removeClass('intersecting');
99+
}
100+
}

docs/src/examples/query/visibility/query-is-in-view/page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ function checkViewportStatus(options = {}) {
2424
if (isVisible) {
2525
$element.addClass('in-viewport');
2626
}
27-
else if ($element.isInViewport()) {
27+
else if ($element.isInView()) {
2828
$element.addClass('partially-visible');
2929
}
3030
});
3131

3232
// Check all elements together
33-
const allVisible = $('.test-element').isInViewport(options);
33+
const allVisible = $('.test-element').isInView(options);
3434
info += `\nAll elements visible in container: ${allVisible ? '✓ YES' : '✗ NO'}`;
3535

3636
$('#viewport-info').text(info);

0 commit comments

Comments
 (0)