You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+63-18Lines changed: 63 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,20 @@
1
-
# Svelte-Headroom
1
+
# @taocode/Svelte-Headroom
2
2
3
3
**Hide your header and footer until you need it!**
4
4
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/).
6
6
7
7
`@taocode/svelte-headroom` has **no dependencies**.
8
8
9
9
## Demo
10
10
11
-
[Svelte REPL](https://svelte.dev/repl/44cafd471bcf497080e12ed3bee80986?version=3.53.1) or check the source: `src/routes/+page.svelte`
[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`
12
14
13
15
## Install
14
16
15
-
`npm install @taocode/svelte-headroom`
17
+
`pnpm install -D @taocode/svelte-headroom`
16
18
17
19
## Usage
18
20
@@ -29,7 +31,7 @@ Svelte Headroom is a [Svelte](https://svelte.dev) component to hide or show your
29
31
30
32
## Props
31
33
32
-
### `tolerance` number
34
+
### `tolerance` number {#tolerance}
33
35
34
36
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`.
35
37
@@ -40,7 +42,7 @@ The number of pixels that need to be scrolled in either direction for the effect
40
42
</Headroom>
41
43
42
44
```
43
-
### `offsetTop` number
45
+
### `offsetTop` number {#offsetTop}
44
46
45
47
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`.
46
48
@@ -52,7 +54,7 @@ The number of pixels from the top of the page before the effect is allowed to oc
52
54
53
55
```
54
56
55
-
### `offsetBottom` number
57
+
### `offsetBottom` number {#offsetBottom}
56
58
57
59
The number of pixels from bottom to be considered at the bottom; *controls*`class:atBottom` (useful with hideAtBottom, showAtBottom). Default: `2`.
58
60
@@ -64,7 +66,7 @@ The number of pixels from bottom to be considered at the bottom; *controls* `cla
64
66
65
67
```
66
68
67
-
### `duration` string
69
+
### `duration` string {#duration}
68
70
69
71
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"`.
70
72
@@ -76,7 +78,7 @@ The duration of the sliding effect. The value is passed on as a [CSS Transition
76
78
77
79
```
78
80
79
-
### `easing` string
81
+
### `easing` string {#easing}
80
82
81
83
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"`.
82
84
@@ -88,31 +90,74 @@ The timing function (easing) of the sliding effect. The value is passed on as a
88
90
89
91
```
90
92
91
-
### `bottom` boolean
93
+
### `bottom` boolean {#bottom}
92
94
93
95
If this is to be pinned to the bottom, like a return to top button. Default: `false`.
94
96
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
+
95
101
```html
96
102
97
-
<Headroombottom>
98
-
<!-- pinned to the bottom -->
99
-
</Headroom>
103
+
<divclass="totop-wrap">
104
+
<Headroombottom>
105
+
<!-- pinned to the bottom -->
106
+
</Headroom>
107
+
</div>
100
108
101
109
```
102
110
103
-
### `(show|hide)At(Top|Bottom)` boolean
111
+
### `(show|hide)At(Top|Bottom)` boolean {#ats}
104
112
105
113
If this is to be pinned to the bottom, like a return to top button. Default: `false`.
106
114
115
+
*Note:* bottom detection fails on [SVELTE REPL]().
116
+
107
117
```html
108
118
109
119
<HeadroomshowAtBottom>
110
120
<!-- my header that will always show when at bottom -->
0 commit comments