-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathview.js
50 lines (47 loc) · 1.48 KB
/
view.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// when window has fully loaded
window.onload = () => {
// select every element with the className of : "value"
const myElement = document.querySelectorAll(".value");
// trigger actions each time user scrolls the page
window.addEventListener("scroll", () => {
// get the screen height (viewport height)
const viewportHeight =
window.innerHeight || document.documentElement.clientHeight;
// sniff out the values returned from getBoundingClientRect()
const {
height,
left,
right,
top,
bottom,
width,
x,
y,
} = document.getElementById("element").getBoundingClientRect();
// print out the values on every element matching the selector
myElement.forEach((element) => {
// for every element (.value class elements)
// cook some magic
element.innerHTML = `
<div>
<span>height : ${height}</span>
<span>left : ${left}</span>
<span>right : ${right}</span>
<span>top : ${top}</span>
<span>bottom : ${bottom}</span>
<span>width : ${width}</span>
<span>x : ${x}</span>
<span>y : ${y}</span>
<span> PartiallyVisible : ${
viewportHeight - top > 0 && bottom > 0 ? "true" : "false"
}</span>
<span> IsFullyVisible : ${
bottom > 0 && bottom <= viewportHeight && top >= 0
? "true"
: "false"
}</span>
</div>
`;
});
});
};