Coder Social home page Coder Social logo

ssense / vue-scroll-magnet Goto Github PK

View Code? Open in Web Editor NEW
16.0 14.0 2.0 183 KB

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

JavaScript 26.52% HTML 51.29% Vue 22.19%
vue sticky scroll

vue-scroll-magnet's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.