Skip to content

A Svelte component to hide your header on scroll.

Notifications You must be signed in to change notification settings

codepainting/svelte-headroom

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Svelte-Headroom

Hide your header until you need it!

Svelte Headroom is a Svelte component to hide or show your header on scroll, inspired by headroom.js

svelte-headroom has no dependencies.

Demo

Code Sandbox

Install

npm install svelte-headroom

Usage

<script>
  import Headroom from "svelte-headroom";
</script>

<Headroom>
  <!-- my header -->
</Headroom>

Props

offset number

The number of pixels from the top of the page before the effect is allowed to occur. The default value is 0.

<Headroom offset={50}>
  <!-- my header -->
</Headroom>

tolerance number

The amount 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. The default value is 0.

<Headroom tolerance={10}>
  <!-- my header -->
</Headroom>

duration string

The duration of the sliding effect. The value is passed on as a CSS Transition Duration. The default value is "300ms".

<Headroom duration='500ms'>
  <!-- my header -->
</Headroom>

Events

A svelte-headroom component emits two events: pin and unpin.

<Headroom
  on:pin={ () => {} }
  on:unpin={ () => {} }
>
  <header>My Header</header>
</Headroom>

Happy Coding!

About

A Svelte component to hide your header on scroll.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Svelte 60.4%
  • JavaScript 39.6%