Skip to content

Commit d0bc589

Browse files
committed
docs: readme corrections with bottom example
1 parent 4aa5f95 commit d0bc589

File tree

1 file changed

+63
-18
lines changed

1 file changed

+63
-18
lines changed

README.md

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
# Svelte-Headroom
1+
# @taocode/Svelte-Headroom
22

33
**Hide your header and footer until you need it!**
44

5-
Svelte Headroom is a [Svelte](https://svelte.dev) component to hide or show your header on scroll, adapted from [collardeau/svelte-headroom](https://github.com/collardeau/svelte-headroom), inspired by [headroom.js](https://wicky.nillia.ms/headroom.js/)
5+
Svelte Headroom is a [Svelte](https://svelte.dev) component to hide or show your header and footer on scroll, adapted from [collardeau/svelte-headroom](https://github.com/collardeau/svelte-headroom), inspired by [headroom.js](https://wicky.nillia.ms/headroom.js/).
66

77
`@taocode/svelte-headroom` has **no dependencies**.
88

99
## Demo
1010

11-
[Svelte REPL](https://svelte.dev/repl/44cafd471bcf497080e12ed3bee80986?version=3.53.1) or check the source: `src/routes/+page.svelte`
11+
[Svelte REPL](https://svelte.dev/repl/44cafd471bcf497080e12ed3bee80986?version=3.53.1)
12+
13+
[Grab a copy](https://github.com/taocode/svelte-headroom) and play with it directly. Run `pnpm dev` (or yarn, npm equivalents) and edit the demo test page: `src/routes/+page.svelte`
1214

1315
## Install
1416

15-
`npm install @taocode/svelte-headroom`
17+
`pnpm install -D @taocode/svelte-headroom`
1618

1719
## Usage
1820

@@ -29,7 +31,7 @@ Svelte Headroom is a [Svelte](https://svelte.dev) component to hide or show your
2931

3032
## Props
3133

32-
### `tolerance` number
34+
### `tolerance` number {#tolerance}
3335

3436
The number of pixels that need to be scrolled in either direction for the effect to occur. This is useful if you want the user to be able to scroll slowly and not change the header position. Default: `0`.
3537

@@ -40,7 +42,7 @@ The number of pixels that need to be scrolled in either direction for the effect
4042
</Headroom>
4143

4244
```
43-
### `offsetTop` number
45+
### `offsetTop` number {#offsetTop}
4446

4547
The number of pixels from the top of the page before the effect is allowed to occur; *controls:* `class:atTop` (useful with hideAtTop, showAtTop). Default: `2`.
4648

@@ -52,7 +54,7 @@ The number of pixels from the top of the page before the effect is allowed to oc
5254

5355
```
5456

55-
### `offsetBottom` number
57+
### `offsetBottom` number {#offsetBottom}
5658

5759
The number of pixels from bottom to be considered at the bottom; *controls* `class:atBottom` (useful with hideAtBottom, showAtBottom). Default: `2`.
5860

@@ -64,7 +66,7 @@ The number of pixels from bottom to be considered at the bottom; *controls* `cla
6466

6567
```
6668

67-
### `duration` string
69+
### `duration` string {#duration}
6870

6971
The duration of the sliding effect. The value is passed on as a [CSS Transition Duration](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-duration). Default: `"300ms"`.
7072

@@ -76,7 +78,7 @@ The duration of the sliding effect. The value is passed on as a [CSS Transition
7678

7779
```
7880

79-
### `easing` string
81+
### `easing` string {#easing}
8082

8183
The timing function (easing) of the sliding effect. The value is passed on as a [CSS Transition Timing Function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function). Default: `"linear"`.
8284

@@ -88,31 +90,74 @@ The timing function (easing) of the sliding effect. The value is passed on as a
8890

8991
```
9092

91-
### `bottom` boolean
93+
### `bottom` boolean {#bottom}
9294

9395
If this is to be pinned to the bottom, like a return to top button. Default: `false`.
9496

97+
*Note:* you'll need to wrap a bottom pinned Headroom to use it because
98+
it isn't 100% wide to avoid covering links and breaking the UI a bit.
99+
You can play with heights and widths and different positioning; *see below for my favorite .totop-wrap*
100+
95101
```html
96102

97-
<Headroom bottom>
98-
<!-- pinned to the bottom -->
99-
</Headroom>
103+
<div class="totop-wrap">
104+
<Headroom bottom>
105+
<!-- pinned to the bottom -->
106+
</Headroom>
107+
</div>
100108

101109
```
102110

103-
### `(show|hide)At(Top|Bottom)` boolean
111+
### `(show|hide)At(Top|Bottom)` boolean {#ats}
104112

105113
If this is to be pinned to the bottom, like a return to top button. Default: `false`.
106114

115+
*Note:* bottom detection fails on [SVELTE REPL]().
116+
107117
```html
108118

109119
<Headroom showAtBottom>
110120
<!-- my header that will always show when at bottom -->
111121
</Headroom>
112122

113-
<Headroom bottom hideAtTop showAtBottom tolerance={20} shim={50}>
114-
<!-- footer for 'to top' button -->
115-
</Headroom>
123+
<div class="totop-wrap">
124+
<Headroom bottom hideAtTop showAtBottom tolerance={20} shim={50}>
125+
<!-- footer for 'to top' button -->
126+
<button
127+
class="totop"
128+
on:click={()=> window.scroll(0,0)}
129+
>
130+
<span class="caret">^</span> <span>To Top</span>
131+
</button>
132+
</Headroom>
133+
</div>
134+
135+
<style>
136+
.totop-wrap {
137+
max-width: 90ch;
138+
margin: 0 auto;
139+
display: flex;
140+
justify-content: end;
141+
}
142+
.totop {
143+
margin: 2em;
144+
background: hsl(29, 100%, 40%);
145+
color: white;
146+
border: 0;
147+
padding: 0.5rem;
148+
cursor: pointer;
149+
display: flex;
150+
flex-direction: column;
151+
align-items: center;
152+
text-transform: uppercase;
153+
font-size: 0.667em;
154+
line-height: 1.5rem;
155+
}
156+
.caret {
157+
font-size: 4em;
158+
padding-top: 0.5rem;
159+
}
160+
</style>
116161

117162
```
118163

@@ -129,4 +174,4 @@ A `svelte-headroom` component emits two events: `pin` and `unpin`.
129174
</Headroom>
130175
```
131176

132-
Happy Coding!
177+
## Happy Coding! {#happy}

0 commit comments

Comments
 (0)