• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    JavaScript
  • License
    Other
  • Created over 10 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Let's take a scroll!

NPM

Build Status img img styled with prettier

Doormat πŸ‘žπŸ‘‘

an alternative way to traverse through your site content 😎

alt tag

Index

How

The trick is possible by making sections of the page position: fixed and position: absolute whilst setting a height for the container element equal to the combined height of the page sections.

Page sections are given an appropriate top value that gives some buffer space for scrolling and give the parallax like illusion against whichever section is currently position: fixed.

Dependent on the panel mode, as the window is scrolled panels come into or move out of the viewport to either reveal or cover up fixed position content.

Features

  • Provides alternative way to traverse content
  • Configurable behavior
  • Inbound and outbound traversal modes
  • Panel snapping to either viewport or as a means of traversing panels
  • API for programmatically traversing content
  • Responsive
  • Animated scrolling
  • Simple to create custom effects/behavior with CSS with many possibilities.
  • Supports overflowing content in outbound mode(refer to caveatsπŸ˜…)
  • No dependencies! πŸŽ‰
  • Scroll/Resize optimization via requestAnimationFrame

alt tag

Browser support

Chrome Firefox Safari Opera Edge IE
πŸ˜„ πŸ˜„ πŸ˜„ πŸ˜„ πŸ˜„ πŸ˜„

v5 makes use of requestAnimationFrame, viewport units and the Event API. Most browsers should play nice except Opera Mini πŸ‘Ž. IE support should be fine in version 11.

Usage

To create your doormat.

  1. Include doormat{.min}.js and doormat{.min}.css in your page/bundle.

  2. Create your DOM/Page structure. The containing element needs the classname dm. This could be body. doormat uses panels for each section of content. Therefore, the children of our container need the class dm-pnl. ol and ul make good container elements πŸ˜‰ A structure like the following is ideal.

  <body>
    <ol class="dm">
      <li class="dm__pnl">Awesome</li>
      <li class="dm__pnl">Site</li>
      <li class="dm__pnl">Content</li>
    </ol>
    <script src="doormat.min.js"/>
  </body>
  1. Invoke the Doormat function passing in desired options(explained below) as a parameter;
document.addEventListener('DOMContentLoaded', function() {
  var myDoormat = new Doormat();
});

Options

  • {number} snapDebounce - defaults to 150: No need to trigger snapping behavior on every scroll so snapDebounce defines a debouncing duration in ms.
  • {number} scrollDuration - defaults to 250: Defines the default duration in ms that a panel takes to snap to place or the duration of a programmatic doormat scroll that isn't overridden with the optional parameter.
  • {string} snapMode - defaults to 'viewport': Defines the "snap" style of Doormat panels. Whether it be viewport style, travel style or disabled with false. Setting to false will mean that users can scroll content so that it doesn't sit flush in the viewport.
  • {string} mode - defaults to 'outbound': Defines the traversal style. outbound will make panels slide out to the top of the viewport revealing content underneath. inbound will make panels slide in from the bottom covering content.
  • {number} snapThreshold - defaults to 30: Define the percentage of the viewport that will trigger a "snap". For example, you start scrolling a panel but no more than 30% of the viewport height. You stop scrolling and because snapMode is set to viewport, the panel scrolls back to fit flush with the viewport again πŸ‘

alt tag

API

  • {number} activeIndex: Getter for current active panel index. Useful for conditionals where content should only appear at certain times etc.
  • {Object} active: Getter for current active panel element.
  • next: Function to scroll to next panel.
  • prev: Function to scroll to previous panel.
  • {Array} panels: Getter for panels collection.
  • reset: Function to reset Doormat instance. Used on viewport changes. Will instantly scroll to top with no animation and set first panel as active.
  • {number} scrollPos: Getter for current scroll position of instance.
  • scrollTo({number} scrollPosition, ?{number} speed): Function for scrolling to a specific position within instance. Accepts optional speed parameter in ms.
  • scrollToPanel({number} panelIndex, ?{number} speed): Function for scrolling to a specific panel. Accepts optional speed parameter in ms.

alt tag

Events

Doormat offers an even that can be bound to for observing when a new panel becomes active. The event is doormat:update. Consider the following example that can be used for customisation to show controls once scrolled past the first panel 😎

window.addEventListener('doormat:update', (e) => {
  if (doormatInstance.activeIndex > 1)
    document.body.classList.add('show-controls')
  else
    document.body.classList.remove('show-controls')
})

curtain.js?

Unfortunately, curtain.js is no longer maintained and there were reports of issues with newer versions of jQuery.

curtain.js is a more feature rich solution and provides some different behavior and hooks. It does however depend on jQuery.

I was unaware of curtain.js when creating Doormat. Initially, I was experimenting with different implementations of parallax style effects and messing about with viewport units.

My aim with Doormat was to create the effect but keep the solution minimal with no dependencies. It was a result of curiosity and playing with code.

Customisation

UI Effects

One feature I like with Doormat is the ability to create custom effects with relative ease using CSS or conditionally based on the current active panel index of a Doormat instance.

alt tag

For example, the effects in the above GIF are created by leveraging CSS transitions based on the current active panel of an instance. The important parts are;

.dm-panel__content {
  opacity: 0;
  transform: scale(0);
  transition: opacity .25s ease 0s, transform .25s ease 0s;
}

.dm-panel--active .dm-panel__content {
  opacity: 1;
  transform: scale(1);
}

Caveats

  • If you use inbound mode, content larger than the viewport will get cut off as opposed to when using outbound mode. Solution? Make the content of the active panel scrollable πŸ€“
  .dm-panel--active .dm-panel__content {
    overflow: auto;
  }

Roll your own classes

The classes for Doormat are config driven with doormat.config.json. In here you can alter the classnames for elements to your desire.

Important:: If you change the classnames in the config, you will also need to update any reference to them from within the JavaScript source. For example, by altering the classes property on the Doormat class.

Change the config and then run the build task with make build.

Development

Want to play with the code?

  1. Fork and clone or simply clone the repo direct.

     git clone https://github.com/jh3y/doormat.git
    
  2. Navigate into the repo and run the setup task;

     cd doormat
     make setup
    
  3. Run the develop task to get up and running with browser-sync etc.

     make develop
    

NOTE:: See all available build tasks by simply running make in the root of the directory πŸ‘

  make

alt tag

Contributing

Don't hesitate to post an issue or suggestion or get in touch by tweeting me @_jh3y!

License

MIT

jh3y 2017


Images courtesy of Unsplash 🐱

More Repositories

1

whirl

CSS loading animations with minimal effort!
SCSS
1,756
star
2

tyto

manage and organise things
JavaScript
675
star
3

ep

enhance your HTML5 progress bars with minimal effort!
JavaScript
647
star
4

driveway

pure CSS masonry layouts
HTML
632
star
5

vincent-van-git

Use your Github commit history as a canvas!
JavaScript
288
star
6

meanderer

A JavaScript micro-library for responsive CSS motion paths! ✨
JavaScript
223
star
7

sketchbook

The home for all my demo source wherever you may find them! ⚑️
HTML
183
star
8

gulp-boilerplate

a simple gulp boilerplate
JavaScript
146
star
9

kody

.files and environment configuration manager created with node
JavaScript
139
star
10

jh3y

73
star
11

pxl

A React app for drawing pixel art
JavaScript
72
star
12

osaka-card

TypeScript
59
star
13

tips

CSS tooltips!
CSS
47
star
14

jhey.dev

Site source for jhey.dev ✨
JavaScript
47
star
15

a-guide-to-css-animation

Demo code for "A Guide to CSS Animation"
CSS
44
star
16

use-caret-position

A custom React hook for grabbing the caret position in a text input.
JavaScript
37
star
17

parcel-boilerplate

a boilerplate for using Parcel JS 😎
HTML
30
star
18

culr

color search engine
JavaScript
27
star
19

node-cli-boilerplate

a simple boilerplate to get up and running with node cli apps
JavaScript
27
star
20

creatives-directory

A list of creatives to follow on Twitter 🐦
JavaScript
23
star
21

view-transition-sandbox

Sandbox to get creative with the View Transition API
Astro
20
star
22

my-script-kit

JavaScript
20
star
23

move-things-with-css

The accompanying source for "Move Things With CSS"
CSS
20
star
24

focussed-twitter

Let's focus on the tweets! 🐦
JavaScript
17
star
25

subscription-calendar-view-transitions

MPA View Transitions Subscription Calendar
Astro
17
star
26

stationery-cabinet

The repository for the majority of my CodePen creations!
Pug
15
star
27

crayon

a repo for styling CodePen profiles
HTML
14
star
28

deck

Astro
14
star
29

pen-case

A local development boilerplate set up for creating new pens πŸ“
Makefile
12
star
30

sike

a cli app that reminds you to move around every once in a while!
JavaScript
11
star
31

russ

a node scripts runner 🐰
JavaScript
11
star
32

parcel-react-boilerplate

a boilerplate for bundling react applications with Parcel JS
JavaScript
10
star
33

netlify-cms-next-starter

Get up and running with Netlify CMS && Next.js
JavaScript
10
star
34

next-portfolio-starter

A portfolio starting point using Next.js, Netlify CMS, Storybook, and Tailwind
JavaScript
9
star
35

kody_env

My personal settings for kody .files manager
Shell
9
star
36

serverless-og

JavaScript
9
star
37

whac-a-mole-react

JavaScript
9
star
38

dynamic-island

An Astro playground for building a "Dynamic Island" for your site
CSS
9
star
39

round-table

CSS
8
star
40

egghead

a home for my egghead material source πŸ₯š
HTML
7
star
41

campfire

CSS
6
star
42

shooting-stars

HTML5 Canvas play around to create shooting stars effect
JavaScript
6
star
43

houdini-tesla

A CSS Houdini PaintWorklet for Tesla Coils
JavaScript
5
star
44

create-bangle-app

create and develop bangle.js apps from the command line
JavaScript
5
star
45

houdini-noise

CSS Houdini PaintWorklet for background noise
JavaScript
4
star
46

color-image-search-api

JavaScript
4
star
47

astro-mpa-bars

Quick POC for Astro Page Stinger View Transitions
TypeScript
4
star
48

which-key

an app for grabbing JavaScript KeyboardEvent info!
JavaScript
4
star
49

blurbs

Write something about me!
3
star
50

testPlayground

a repo for examples on how to set up mocha
JavaScript
3
star
51

jheymote

Audience remote for Jhey's conference talks
JavaScript
3
star
52

storybook-addon-studybook

Spin your Storybook into a learning aid with trackable progress.
JavaScript
3
star
53

key-book

create frozen enum objects from a string array ❄️
JavaScript
3
star
54

electron-parcel-react-starter

A starter project using Electron, React, and Parcel
JavaScript
3
star
55

border-radius-playground

An interactive visualisation tool for becoming a wizard with border-radius ✨
JavaScript
3
star
56

feedy

an angular app for consuming public photo feeds
JavaScript
3
star
57

inspector-gamut

A POC app for using AI to generate color palettes based on keywords
TypeScript
3
star
58

ng-mega-table

A directive for handling mega data
JavaScript
2
star
59

green-blocks

A Github Activity Visualizer Built with Next.js, React-Three-Fiber, Netlify, Tailwind, and GSAP
JavaScript
2
star
60

react-waves

A React component for making those fancy animated waves!
JavaScript
2
star
61

corvid

interactive command line Github API browser and cloning aid
JavaScript
2
star
62

blokky-road

3D CSS studio built with React on Vite
JavaScript
2
star
63

blink

JavaScript
2
star
64

fusion-hn

Hacker News example app built w/ Fusion JS
JavaScript
2
star
65

html5-boilerplate-jade-less-livereload.docpad

A skeleton for docpad using html5 boilerplate, less and jade.
CoffeeScript
1
star
66

interactive-twitch-overlay

Interactive Twitch Overlays Built with Tailwind && Next.js
JavaScript
1
star
67

sticky

A configurable sticky note component.
JavaScript
1
star
68

nodivember

CSS
1
star
69

blok-party

JavaScript
1
star
70

og-generator

A CLI tool for generating jh3y cover assets.
JavaScript
1
star
71

clinic

Submit your questions and issues for the clinic!
1
star
72

jheytompkins.com

source for
JavaScript
1
star
73

pencil-sharpener

Repo for storing my CodePen profile styling
HTML
1
star
74

next-storyblok-playground

JavaScript
1
star
75

gulp-template-store

a gulp plugin for storing lodash templates in a namespace object
JavaScript
1
star