-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdocs.html
More file actions
749 lines (654 loc) · 24.5 KB
/
Copy pathdocs.html
File metadata and controls
749 lines (654 loc) · 24.5 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Peek Documentation</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--primary: #667eea;
--primary-dark: #5568d3;
--secondary: #764ba2;
--text: #2d3748;
--text-light: #4a5568;
--border: #e2e8f0;
--bg-gray: #f7fafc;
--code-bg: #1e293b;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
line-height: 1.7;
color: var(--text);
background: white;
}
/* Header */
.header-main {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 1000;
background: white;
border-bottom: 1px solid var(--border);
transition: transform 0.3s ease, box-shadow 0.3s ease;
will-change: transform;
}
.main-header--unpinned {
transform: translateY(-100%);
}
.main-header--pinned {
transform: translateY(0);
}
.main-header--top {
box-shadow: none;
}
.main-header--not-top {
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}
.header-content {
max-width: 1400px;
margin: 0 auto;
padding: 1rem 2rem;
display: flex;
justify-content: space-between;
align-items: center;
}
.logo {
font-size: 1.5rem;
font-weight: bold;
color: var(--primary);
display: flex;
align-items: center;
gap: 0.5rem;
text-decoration: none;
}
.logo-icon {
width: 32px;
height: 32px;
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
}
.header-nav {
display: flex;
gap: 2rem;
align-items: center;
}
.header-nav a {
color: var(--text-light);
text-decoration: none;
font-weight: 500;
transition: color 0.2s;
}
.header-nav a:hover {
color: var(--primary);
}
a.github-btn {
padding: 0.5rem 1rem;
background: var(--primary);
color: white !important;
border-radius: 6px;
text-decoration: none;
font-weight: 600;
transition: background 0.2s;
}
a.github-btn:hover {
background: var(--primary-dark);
}
/* Layout */
.container {
max-width: 1400px;
margin: 0 auto;
display: flex;
padding-top: 70px;
}
/* Sidebar */
.sidebar {
width: 280px;
position: sticky;
top: 90px;
height: calc(100vh - 90px);
overflow-y: auto;
padding: 2rem 1rem 2rem 2rem;
border-right: 1px solid var(--border);
background: var(--bg-gray);
}
.sidebar h3 {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 0.05em;
color: var(--text-light);
margin-bottom: 1rem;
font-weight: 700;
}
.sidebar ul {
list-style: none;
margin-bottom: 2rem;
}
.sidebar li {
margin-bottom: 0.5rem;
}
.sidebar a {
color: var(--text-light);
text-decoration: none;
display: block;
padding: 0.5rem;
border-radius: 6px;
transition: all 0.2s;
font-size: 0.9rem;
}
.sidebar a:hover {
background: white;
color: var(--primary);
padding-left: 1rem;
}
.sidebar a.active {
background: var(--primary);
color: white;
font-weight: 600;
}
/* Main Content */
.main-content {
flex: 1;
padding: 2rem 3rem;
min-width: 0;
}
/* Documentation Styles */
.docs h1 {
font-size: 2.5rem;
margin-bottom: 0.5rem;
color: var(--text);
font-weight: 800;
}
.docs h2 {
font-size: 2rem;
margin-top: 3rem;
margin-bottom: 1rem;
color: var(--text);
font-weight: 700;
padding-bottom: 0.5rem;
border-bottom: 2px solid var(--border);
}
.docs h3 {
font-size: 1.5rem;
margin-top: 2rem;
margin-bottom: 1rem;
color: var(--text);
font-weight: 600;
}
.docs h4 {
font-size: 1.25rem;
margin-top: 1.5rem;
margin-bottom: 0.75rem;
color: var(--text);
font-weight: 600;
}
.docs p {
margin-bottom: 1.25rem;
color: var(--text-light);
font-size: 1rem;
}
.docs ul, .docs ol {
margin-bottom: 1.25rem;
padding-left: 1.5rem;
color: var(--text-light);
}
.docs li {
margin-bottom: 0.5rem;
}
.docs strong {
color: var(--text);
font-weight: 600;
}
.docs code {
background: #f1f5f9;
padding: 0.2rem 0.4rem;
border-radius: 4px;
font-family: 'Courier New', monospace;
font-size: 0.9em;
color: #e11d48;
}
.docs pre {
background: var(--code-bg);
color: #e2e8f0;
padding: 1.5rem;
border-radius: 8px;
overflow-x: auto;
margin: 1.5rem 0;
font-family: 'Courier New', monospace;
font-size: 0.9rem;
line-height: 1.6;
}
.docs pre code {
background: none;
padding: 0;
color: inherit;
font-size: inherit;
}
.docs table {
width: 100%;
border-collapse: collapse;
margin: 1.5rem 0;
font-size: 0.9rem;
}
.docs table thead {
background: var(--bg-gray);
}
.docs table th {
padding: 0.75rem;
text-align: left;
font-weight: 600;
color: var(--text);
border-bottom: 2px solid var(--border);
}
.docs table td {
padding: 0.75rem;
border-bottom: 1px solid var(--border);
color: var(--text-light);
}
.docs table tbody tr:hover {
background: var(--bg-gray);
}
.badge {
display: inline-block;
padding: 0.25rem 0.75rem;
background: var(--bg-gray);
border-radius: 20px;
font-size: 0.875rem;
font-weight: 600;
color: var(--text-light);
margin-right: 0.5rem;
margin-bottom: 0.5rem;
}
.badge.badge-primary {
background: var(--primary);
color: white;
}
.info-box {
background: #dbeafe;
border-left: 4px solid #3b82f6;
padding: 1rem 1.5rem;
margin: 1.5rem 0;
border-radius: 4px;
}
.info-box p {
margin: 0;
color: #1e40af;
}
/* Mobile Styles */
@media (max-width: 1024px) {
.sidebar {
display: none;
}
.main-content {
padding: 2rem 1.5rem;
}
.docs h1 {
font-size: 2rem;
}
.docs h2 {
font-size: 1.5rem;
}
}
/* Smooth Scrolling */
html {
scroll-behavior: smooth;
}
/* Mobile Menu Toggle */
.mobile-menu-btn {
display: none;
background: var(--primary);
color: white;
border: none;
padding: 0.5rem 1rem;
border-radius: 6px;
cursor: pointer;
font-weight: 600;
}
@media (max-width: 1024px) {
.mobile-menu-btn {
display: block;
}
.header-nav > a:not(.github-btn) {
display: none;
}
}
</style>
</head>
<body>
<!-- Header -->
<header class="header-main">
<div class="header-content">
<a href="#" class="logo">
<div class="logo-icon">P</div>
Peek
</a>
<nav class="header-nav">
<a href="/Peek/">Overview</a>
<a href="#introduction">Docs</a>
<a href="#examples">Examples</a>
<a href="#api-methods">API</a>
<a href="https://github.com/adesignl/Peek" class="github-btn">GitHub</a>
</nav>
</div>
</header>
<div class="container">
<!-- Sidebar -->
<aside class="sidebar">
<h3>Getting Started</h3>
<ul>
<li><a href="#introduction">Introduction</a></li>
<li><a href="#features">Features</a></li>
<li><a href="#installation">Installation</a></li>
<li><a href="#quick-start">Quick Start</a></li>
</ul>
<h3>Configuration</h3>
<ul>
<li><a href="#configuration-options">Options</a></li>
<li><a href="#how-it-works">How It Works</a></li>
<li><a href="#state-classes">State Classes</a></li>
</ul>
<h3>API Reference</h3>
<ul>
<li><a href="#api-methods">Methods</a></li>
</ul>
<h3>Examples</h3>
<ul>
<li><a href="#examples">Basic Usage</a></li>
<li><a href="#example-custom">Custom Config</a></li>
<li><a href="#example-mobile">Mobile Only</a></li>
</ul>
<h3>Additional Info</h3>
<ul>
<li><a href="#browser-support">Browser Support</a></li>
<li><a href="#performance">Performance</a></li>
<li><a href="#contributing">Contributing</a></li>
</ul>
</aside>
<!-- Main Content -->
<main class="main-content">
<article class="docs">
<section id="introduction">
<h1>Peek</h1>
<p>
<span class="badge badge-primary">v1.0.0</span>
<span class="badge">MIT License</span>
<span class="badge">No Dependencies</span>
</p>
<p>A lightweight JavaScript library for creating smart header behavior based on scroll intent. Peek automatically hides your site header when users scroll down and reveals it when they scroll up, creating a more immersive browsing experience.</p>
<p><strong>Author:</strong> Chad Pierce<br>
<strong>Copyright:</strong> A Design Link, LLC</p>
</section>
<section id="features">
<h2>Features</h2>
<ul>
<li><strong>Lightweight</strong> - Minimal footprint with no dependencies</li>
<li><strong>Smart scroll detection</strong> - Distinguishes between intentional scrolling and small movements</li>
<li><strong>Smooth animations</strong> - Uses requestAnimationFrame for optimal performance</li>
<li><strong>Easy integration</strong> - Works with any website or framework</li>
<li><strong>Customizable</strong> - Configure thresholds, delays, and CSS classes</li>
<li><strong>Passive event listeners</strong> - Improved scroll performance</li>
</ul>
</section>
<section id="installation">
<h2>Installation</h2>
<h3>Manual</h3>
<p>Download <code>peek.js</code> or <code>peek.min.js</code> and include it in your project.</p>
<pre><code><script src="path/to/peek.js"></script></code></pre>
</section>
<section id="quick-start">
<h2>Quick Start</h2>
<h3>HTML</h3>
<pre><code><header class="header-main">
Your header content
</header></code></pre>
<h3>CSS</h3>
<pre><code>.header-main {
position: fixed;
top: 0;
left: 0;
right: 0;
transition: transform 0.3s ease;
will-change: transform;
}
.main-header--unpinned {
transform: translateY(-100%);
}
.main-header--pinned {
transform: translateY(0);
}
.main-header--top {
/* Styles when at top of page */
}
.main-header--not-top {
/* Styles when scrolled past offset */
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}</code></pre>
<h3>JavaScript</h3>
<pre><code>// Initialize with default options
const peek = Peek('.header-main');
// Or customize the behavior
const peek = Peek('.header-main', {
offset: 150,
tolerance: 10,
classes: {
pinned: 'main-header--pinned',
unpinned: 'main-header--unpinned',
top: 'main-header--top',
notTop: 'main-header--not-top'
}
});</code></pre>
</section>
<section id="configuration-options">
<h2>Configuration Options</h2>
<table>
<thead>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>offset</code></td>
<td>Number</td>
<td><code>100</code></td>
<td>Scroll offset in pixels before triggering state changes</td>
</tr>
<tr>
<td><code>tolerance</code></td>
<td>Number</td>
<td><code>5</code></td>
<td>Pixels scrolled before pin/unpin state change</td>
</tr>
<tr>
<td><code>classes.pinned</code></td>
<td>String</td>
<td><code>'main-header--pinned'</code></td>
<td>Class applied when header is visible/pinned</td>
</tr>
<tr>
<td><code>classes.unpinned</code></td>
<td>String</td>
<td><code>'main-header--unpinned'</code></td>
<td>Class applied when header is hidden/unpinned</td>
</tr>
<tr>
<td><code>classes.top</code></td>
<td>String</td>
<td><code>'main-header--top'</code></td>
<td>Class applied when at top of page (≤ offset)</td>
</tr>
<tr>
<td><code>classes.notTop</code></td>
<td>String</td>
<td><code>'main-header--not-top'</code></td>
<td>Class applied when scrolled past offset</td>
</tr>
</tbody>
</table>
</section>
<section id="how-it-works">
<h2>How It Works</h2>
<p>Peek uses a smart scroll detection algorithm:</p>
<ol>
<li><strong>Top Detection:</strong> When scroll position is at or below the <code>offset</code>, the header stays pinned and gets the <code>top</code> class</li>
<li><strong>Scroll Direction:</strong> Detects whether user is scrolling up or down</li>
<li><strong>Tolerance Check:</strong> Only triggers state changes after scrolling at least <code>tolerance</code> pixels to avoid jitter</li>
<li><strong>State Management:</strong> Applies appropriate classes based on scroll direction and position</li>
</ol>
</section>
<section id="state-classes">
<h3>State Classes</h3>
<ul>
<li><strong><code>main-header--top</code>:</strong> Applied when <code>scrollY ≤ offset</code> (at top of page)</li>
<li><strong><code>main-header--not-top</code>:</strong> Applied when <code>scrollY > offset</code> (scrolled past threshold)</li>
<li><strong><code>main-header--pinned</code>:</strong> Applied when header should be visible (scrolling up or at top)</li>
<li><strong><code>main-header--unpinned</code>:</strong> Applied when header should be hidden (scrolling down)</li>
</ul>
</section>
<section id="api-methods">
<h2>API Methods</h2>
<h3><code>peek.destroy()</code></h3>
<p>Remove event listeners and clean up all classes.</p>
<pre><code>const peek = Peek('.header-main');
// Later, when you want to remove Peek
peek.destroy();</code></pre>
</section>
<section id="examples">
<h2>Examples</h2>
<h3 id="example-basic">Example 1: Basic Implementation</h3>
<pre><code>// Using default settings
const peek = Peek('.header-main');</code></pre>
<h3 id="example-custom">Example 2: Custom Offset and Tolerance</h3>
<pre><code>// More sensitive to scroll changes
const peek = Peek('.header-main', {
offset: 150,
tolerance: 10
});</code></pre>
<h3>Example 3: Custom Classes</h3>
<pre><code>// Use your own class naming convention
const peek = Peek('.site-header', {
classes: {
pinned: 'header-visible',
unpinned: 'header-hidden',
top: 'at-top',
notTop: 'scrolled'
}
});</code></pre>
<h3 id="example-mobile">Example 4: Mobile-Only Implementation</h3>
<pre><code>let peek;
function initPeekOnMobile() {
if (window.innerWidth < 768 && !peek) {
peek = Peek('.header-main');
} else if (window.innerWidth >= 768 && peek) {
peek.destroy();
peek = null;
}
}
// Initialize
initPeekOnMobile();
// Handle window resize
window.addEventListener('resize', initPeekOnMobile);</code></pre>
<h3>Example 5: Multiple Headers</h3>
<pre><code>// Apply to multiple headers with different settings
const mainPeek = Peek('.header-main', { offset: 100 });
const subPeek = Peek('.header-sub', { offset: 200, tolerance: 10 });</code></pre>
</section>
<section id="browser-support">
<h2>Browser Support</h2>
<p>Peek works in all modern browsers that support:</p>
<ul>
<li><code>requestAnimationFrame</code></li>
<li><code>classList</code> API</li>
<li>Passive event listeners</li>
</ul>
<p>Supported browsers:</p>
<ul>
<li>Chrome/Edge (latest)</li>
<li>Firefox (latest)</li>
<li>Safari (latest)</li>
<li>Opera (latest)</li>
</ul>
</section>
<section id="performance">
<h2>Performance</h2>
<p>Peek is optimized for performance:</p>
<ul>
<li>Uses <code>requestAnimationFrame</code> for smooth updates</li>
<li>Implements passive event listeners for better scroll performance</li>
<li>Minimizes DOM operations with state tracking</li>
<li>Only updates when necessary (tolerance check)</li>
</ul>
</section>
<section id="contributing">
<h2>Contributing</h2>
<p>Contributions are welcome! Please feel free to submit a Pull Request.</p>
<ol>
<li>Fork the repository</li>
<li>Create your feature branch (<code>git checkout -b feature/AmazingFeature</code>)</li>
<li>Commit your changes (<code>git commit -m 'Add some AmazingFeature'</code>)</li>
<li>Push to the branch (<code>git push origin feature/AmazingFeature</code>)</li>
<li>Open a Pull Request</li>
</ol>
</section>
<section>
<h2>License</h2>
<p>This project is licensed under the MIT License - see the <a href="https://github.com/adesignl/Peek/blob/main/LICENSE" style="color: var(--primary);">LICENSE</a> file for details.</p>
</section>
<section>
<h2>Acknowledgments</h2>
<p>Inspired by the <a href="https://github.com/WickyNilliams/headroom.js" style="color: var(--primary);">Headroom.js</a> library, Peek provides a lightweight alternative with modern JavaScript practices.</p>
</section>
<section>
<h2>Support</h2>
<p>If you have any questions or run into issues, please <a href="https://github.com/adesignl/Peek/issues" style="color: var(--primary);">open an issue</a> on GitHub.</p>
<hr style="margin: 2rem 0; border: none; border-top: 1px solid var(--border);">
<p style="text-align: center; color: var(--text-light);">Made with ❤️ by <a href="https://github.com/adesignl" style="color: var(--primary);">A Design Link, LLC</a></p>
</section>
</article>
</main>
</div>
<!-- Peek Library -->
<script defer src="https://adesignl.github.io/Peek/src/peek.js"></script>
<script defer>
// Initialize Peek
document.addEventListener('DOMContentLoaded', function() {
Peek('.header-main');
// Highlight active section in sidebar
const observerOptions = {
root: null,
rootMargin: '-20% 0px -70% 0px',
threshold: 0
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const id = entry.target.getAttribute('id');
document.querySelectorAll('.sidebar a').forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${id}`) {
link.classList.add('active');
}
});
}
});
}, observerOptions);
document.querySelectorAll('section[id]').forEach(section => {
observer.observe(section);
});
});
</script>
</body>
</html>