|
1 | 1 | <script> |
2 | | - import { |
3 | | - Headroom |
4 | | - } from '$lib' |
| 2 | + import { Headroom } from '$lib' |
5 | 3 |
|
6 | 4 | function onPin() { |
7 | 5 | console.log('pin') |
|
13 | 11 | pinned = false |
14 | 12 | } |
15 | 13 |
|
16 | | - const props = ['tolerance','offsetTop','offsetBottom','duration','easing','bottom',['ats','(hide|show)at(Top|Bottom)']] |
| 14 | + const propsMenu = ['tolerance','offsetTop','offsetBottom','duration','easing','bottom',['ats','(hide|show)at(Top|Bottom)']] |
17 | 15 | let pinned = true |
18 | 16 | </script> |
19 | 17 |
|
|
27 | 25 | <div class="topmenu"> |
28 | 26 | <div class="label">props:</div> |
29 | 27 | <nav class="menu"> |
30 | | - {#each props as p} |
| 28 | + {#each propsMenu as p} |
31 | 29 | {#if Array.isArray(p)} |
32 | 30 | <a href="#{p[0]}">{p[1]}</a> |
33 | 31 | {:else} |
|
40 | 38 | </Headroom> |
41 | 39 |
|
42 | 40 | <div class="totop-wrap"> |
43 | | - <Headroom bottom showAtBottom hideAtTop tolerance={20} offsetTop={200} offsetBottom={100}> |
| 41 | + <Headroom bottom showAtBottom hideAtTop tolerance={20} offsetTop={100} offsetBottom={100}> |
44 | 42 | <button class="totop" on:click={()=> window.scroll(0,0)}> <span class="caret">^</span> <span>To Top</span> </button> |
45 | 43 | </Headroom> |
46 | 44 | </div> |
|
53 | 51 | by <a href="https://wicky.nillia.ms/headroom.js/" rel="nofollow">headroom.js</a></p> |
54 | 52 | <p><code>@taocode/svelte-headroom</code> has <strong>no dependencies</strong>.</p> |
55 | 53 | <h2>Demo</h2> |
56 | | - <p><a href="https://svelte.dev/repl/44cafd471bcf497080e12ed3bee80986" rel="nofollow">SVELTE REPL</a></p> |
| 54 | + <p><a href="https://svelte.dev/repl/44cafd471bcf497080e12ed3bee80986?version=3" rel="nofollow">SVELTE REPL</a></p> |
57 | 55 | <h2>Install</h2> |
58 | 56 | <p><code>npm install @taocode/svelte-headroom</code></p> |
59 | 57 | <h2>Usage</h2> |
|
70 | 68 | <h2>Props</h2> |
71 | 69 | <h3 id="tolerance"><code>tolerance</code> number</h3> |
72 | 70 | <p>The number of pixels that need to be scrolled in either direction for the effect to occur. This is useful if you |
73 | | - want the user to be able to scroll slowly and not trigger . Default: <code>0</code>.</p> |
| 71 | + want the user to be able to scroll slowly and not trigger un/pin event. Default: <code>0</code>.</p> |
74 | 72 | <div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto"> |
75 | 73 | <pre> |
76 | 74 | <span class="pl-kos"><</span><span class="pl-ent">Headroom</span> <span class="pl-c1">tolerance</span>=<span class="pl-s">{10}</span><span class="pl-kos">></span> |
77 | | - <span class="pl-c"><!-- my header --></span> |
| 75 | + <span class="pl-c"><!-- will ignore any scroll less than 10px --></span> |
78 | 76 | <span class="pl-kos"></</span><span class="pl-ent">Headroom</span><span class="pl-kos">></span></pre> |
79 | 77 | </div> |
80 | 78 | <h3 id="offsetTop"><code>offsetTop</code> number</h3> |
81 | | - <p>The number of pixels from the top of the page before the effect is allowed to occur and is the threshold for class:atTop. Default: <code>2</code>.</p> |
| 79 | + <p>The number of pixels from the top of the page before the effect is allowed to occur; <em>controls</em> `class:atTop` (used with hideAtTop, showAtTop) Default: <code>2</code>.</p> |
82 | 80 | <div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto"> |
83 | 81 | <pre> |
84 | 82 | <span class="pl-kos"><</span><span class="pl-ent">Headroom</span> <span class="pl-c1">offsetTop</span>=<span class="pl-s">{50}</span><span class="pl-kos">></span> |
85 | | - <span class="pl-c"><!-- my header --></span> |
| 83 | + <span class="pl-c"><!-- will show until after 50px from top --></span> |
86 | 84 | <span class="pl-kos"></</span><span class="pl-ent">Headroom</span><span class="pl-kos">></span></pre> |
87 | 85 | </div> |
88 | 86 | <h3 id="offsetBottom"><code>offsetBottom</code> number</h3> |
89 | | - <p>The number of pixels from top to still be considered at the bottom (useful with hideAtTop, showAtTop, etc...). |
| 87 | + <p>The number of pixels from top to still be considered at the bottom; <em>controls:</em> `class:atBottom` (used with hideAtBottom, showAtBottom). |
90 | 88 | Default: <code>2</code>.</p> |
91 | 89 | <div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto"> |
92 | 90 | <pre> |
93 | | - <span class="pl-kos"><</span><span class="pl-ent">Headroom</span> <span class="pl-c1">offsetBottom</span>=<span class="pl-s">{5}</span><span class="pl-kos">></span> |
94 | | - <span class="pl-c"><!-- my header --></span> |
| 91 | + <span class="pl-kos"><</span><span class="pl-ent">Headroom</span> showAtBottom <span class="pl-c1">offsetBottom</span>=<span class="pl-s">{150}</span><span class="pl-kos">></span> |
| 92 | + <span class="pl-c"><!-- will show when within 150px of bottom --></span> |
95 | 93 | <span class="pl-kos"></</span><span class="pl-ent">Headroom</span><span class="pl-kos">></span></pre> |
96 | 94 | </div> |
97 | 95 | <h3 id="duration"><code>duration</code> string</h3> |
|
101 | 99 | <div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto"> |
102 | 100 | <pre> |
103 | 101 | <span class="pl-kos"><</span><span class="pl-ent">Headroom</span> <span class="pl-c1">duration</span>='<span class="pl-s">500ms</span>'<span class="pl-kos">></span> |
104 | | - <span class="pl-c"><!-- my header --></span> |
| 102 | + <span class="pl-c"><!-- will take 500ms to transition --></span> |
105 | 103 | <span class="pl-kos"></</span><span class="pl-ent">Headroom</span><span class="pl-kos">></span></pre> |
106 | 104 | </div> |
107 | 105 |
|
|
112 | 110 | <div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto"> |
113 | 111 | <pre> |
114 | 112 | <span class="pl-kos"><</span><span class="pl-ent">Headroom</span> <span class="pl-c1">easing</span>='<span class="pl-s">ease-out</span>'<span class="pl-kos">></span> |
115 | | - <span class="pl-c"><!-- my header --></span> |
| 113 | + <span class="pl-c"><!-- will ease-out --></span> |
116 | 114 | <span class="pl-kos"></</span><span class="pl-ent">Headroom</span><span class="pl-kos">></span></pre> |
117 | 115 | </div> |
118 | 116 |
|
|
121 | 119 | <div class="highlight highlight-text-html-basic notranslate position-relative overflow-auto"> |
122 | 120 | <pre> |
123 | 121 | <span class="pl-kos"><</span><span class="pl-ent">Headroom</span> <span class="pl-c1">bottom</span><span class="pl-kos">></span> |
124 | | - <span class="pl-c"><!-- my header --></span> |
| 122 | + <span class="pl-c"><!-- pinned to the bottom --></span> |
125 | 123 | <span class="pl-kos"></</span><span class="pl-ent">Headroom</span><span class="pl-kos">></span></pre> |
126 | 124 | </div> |
127 | 125 |
|
|
183 | 181 | } |
184 | 182 | .topmenu .label { |
185 | 183 | text-transform: uppercase; |
| 184 | + transform: rotate(-45deg) scaleX(0.85) skewX(-20deg); |
186 | 185 | } |
| 186 | + @media screen and (min-width: 700px) { |
| 187 | + .topmenu .label { |
| 188 | + transform: rotate(0); |
| 189 | + } |
| 190 | + } |
187 | 191 | |
188 | 192 | .menu { |
189 | 193 | display: flex; |
|
0 commit comments