-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
128 lines (118 loc) · 3.78 KB
/
index.html
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!-- @format -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="A light weight, pure javascript plugin used to determine whether an element is in the viewport."
/>
<meta
name="keywords"
content="inViewport, javascript inViewport, javascript-inViewport, viewport, js viewport plugin, js-inViewport, Ian Rogren, ianrogren, javascript, viewport"
/>
<meta name="robots" content="index, follow" />
<title>inViewport</title>
<!-- Stylesheets -->
<link rel="stylesheet" href="stylesheets/viewport-example.css" />
<link
href="https://fonts.googleapis.com/css2?family=Muli:wght@400;700&display=swap"
rel="stylesheet"
/>
<link
href="https://unpkg.com/nord-highlightjs@0.1.0/dist/nord.css"
rel="stylesheet"
type="text/css"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css"
/>
<!-- Scritps -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.3/highlight.min.js"></script>
<script type="text/javascript" src="./viewport-example.min.js"></script>
<script>
hljs.initHighlightingOnLoad();
</script>
</head>
<body>
<header>
<h1><i class="far fa-eye"></i> inViewport</h1>
<p>
A light weight, simple, pure javascript plugin used to determine whether
an element is in the viewport.
</p>
</header>
<main>
<h2>Using inViewport</h2>
<p>
The following are two examples of how to apply inviewport to an element.
Feel free to hop on over to the
<a href="https://github.com/ianrogren/javascript-inViewport/"
>inViewport github</a
>
page for more information.
</p>
<pre>
<code class="javascript">
/**
* Toggle example.
* The threshold is set to one in this example so once the element
* is fully visible the first callback is fired. The second callback
* is then fired if the element is no longer fully visible.
*/
const selectorA = document.getElementById('selector-a');
inViewport(selectorA, 1,
[
() => {
selectorA.classList.add('visible');
console.log('The element is now visible!');
},
() => {
selectorA.classList.remove('visible');
console.log('The element is now hidden.')
},
]
);
/**
* Static example.
* The threshold in this example is set to 0.5 so once the element
* is 50% visible, the callback is fired.
*/
const selectorB = document.getElementById('selector-b');
inViewport(selectorB, 0.5, () => {
selectorB.classList.add('visible');
console.log('The element is now visible!');
});
</code>
</pre>
<!-- Vertical Example -->
<div class="example-wrapper">
<div class="arrow-container">
<h2>Scroll down to test.</h2>
<p>Toggle Example</p>
<i class="far fa-arrow-alt-circle-down"></i>
</div>
<section class="vertical-scroll-example"></section>
</div>
<!-- Horizontal Example -->
<div class="example-wrapper">
<section class="horizontal-scroll-example"></section>
</div>
<!-- Horizontal Notification -->
<div class="example-wrapper horizontal-notification">
<div class="arrow-container">
<h2>Scroll right to test.</h2>
<p>Static example</p>
<i class="far fa-arrow-alt-circle-right"></i>
</div>
</div>
<!-- ¯\_(ツ)_/¯ -->
<div class="shrug">
<i class="far fa-grimace"></i>
</div>
</main>
</body>
</html>