Skip to content

Wrappers for Vue components which follow the viewport while scrolling within the bounds of their parent container

Notifications You must be signed in to change notification settings

SSENSE/vue-scroll-magnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3b938cc · Mar 10, 2017

History

35 Commits
Nov 28, 2016
Mar 10, 2017
Feb 2, 2017
Mar 10, 2017
Feb 2, 2017
Nov 17, 2016
Nov 17, 2016
Nov 17, 2016
Jan 12, 2017
Nov 25, 2016
Nov 25, 2016
Nov 22, 2016
Mar 10, 2017
Feb 28, 2017

Repository files navigation

vue-scroll-magnet

What is Vue Scroll Magnet?

Vue Scroll Magnet is a pair of component wrappers which allow elements to follow the viewport while scrolling and then anchor at the upper and lower extremeties of their parent container. This module is inspired by a jQuery plugin called Sticky kit.

Installation

This component relies on ES6 and may not be compatible with Vue 1.x projects.

npm install -S vue-scroll-magnet

Usage (Global)

Install the components globally:

import Vue from 'vue';
import VueScrollMagnet from 'vue-scroll-magnet';

Vue.use(VueScrollMagnet);

Usage (Component)

Include the wrappers into your component using import:

/* inside your Vue component's script tag */

import { ScrollMagnetContainer, ScrollMagnetItem } from 'vue-scroll-magnet';

export default {
  ...
  components: {
    ScrollMagnetContainer,
    ScrollMagnetItem
  }
  ...
};

HTML structure

The scrollable height boundary will be determined as the direct parent of the <scroll-magnet-container> by default, however it can be configured using an element selector which it can use as a fixed context.

In the example below, <scroll-magnet-container> will automatically use the top of #app as its upper boundary and its height of 500px as its lower boundary unless a specific element context is provided.

<div id="app" style="height: 500px;">
  <scroll-magnet-container>
    <scroll-magnet-item>This content will scroll</scroll-magnet-item>
  </scroll-magnet-container>
</div>

Tests

To run unit tests & code coverage:

npm test

About

Wrappers for Vue components which follow the viewport while scrolling within the bounds of their parent container

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published