|
4 | 4 |
|
5 | 5 | export let duration = '300ms' |
6 | 6 | export let easing = 'linear' |
7 | | - export let offset = 0 |
8 | | - export let toleranceScroll = 0 |
9 | | - export let toleranceTop = 2 |
10 | | - export let toleranceBottom = 2 |
| 7 | + export let offsetTop = 2 |
| 8 | + export let offsetBottom = 2 |
| 9 | + export let tolerance = 0 |
11 | 10 | export let bottom = false |
12 | 11 | export let hideAtBottom = false |
13 | 12 | export let hideAtTop = false |
|
21 | 20 | let atTop = true |
22 | 21 | let atBottom = false |
23 | 22 | let style = `--duration:${duration}; --easing:${easing};` |
24 | | - |
25 | | - validate({ duration, easing, offset, toleranceScroll, toleranceTop, toleranceBottom }) |
| 23 | +
|
| 24 | + validate({ duration, easing, tolerance, offsetTop, offsetBottom }) |
26 | 25 |
|
27 | 26 | const dispatch = createEventDispatcher() |
28 | 27 |
|
|
35 | 34 | }) |
36 | 35 |
|
37 | 36 | function deriveClass(y = 0, scrolled = 0) { |
38 | | - if (y < offset) return 'pin' |
39 | | - if (!scrolled || Math.abs(scrolled) < toleranceScroll) return headerClass |
| 37 | + if (y < offsetTop) return 'pin' |
| 38 | + if (!scrolled || Math.abs(scrolled) < tolerance) return headerClass |
40 | 39 | const dir = scrolled < 0 ? 'down' : 'up' |
41 | 40 | if (dir === 'up') return 'pin' |
42 | 41 | if (dir === 'down') return 'unpin' |
|
52 | 51 |
|
53 | 52 | $: { |
54 | 53 | headerClass = updateClass(y) |
55 | | - atTop = y <= toleranceTop |
56 | | - atBottom = win && win.innerHeight + win.pageYOffset >= document.body.offsetHeight - toleranceBottom |
| 54 | + atTop = y <= offsetTop |
| 55 | + atBottom = win && win.innerHeight + win.pageYOffset >= document.body.offsetHeight - offsetBottom |
57 | 56 | if (headerClass !== lastHeaderClass) { |
58 | 57 | dispatch(headerClass) |
59 | 58 | } |
|
0 commit comments