Giter VIP home page Giter VIP logo

pin.js's Introduction

Pin.js

Finally a dependency free Pin plugin!

Pin.js pins (duh) your elements as you scroll.

It works on all standard modern browsers, and also supports mobile devices smoothly! (Safari on IOS and Chrome on Android)

Install

You can install it using Bower

bower install pin.js

Or you can clone/download the project.

Usage

With JS

1 - Import the pin.js script

<script src="bower_components/pin.js/dist/pin.min.js"></script>

2 - Setup an element

<div id="pin"></div>

3 - Pin it!

new Pin('#pin');

// You can use a DOM reference as well
new Pin(document.getElementById('pin'));

Without JS

1 - Import the pin.js script

<script src="bower_components/pin.js/dist/pin.min.js"></script>

2 - Setup an element with a data-pin attribute

<div id="pin" data-pin></div>

3 - After that you have to... wait! there's no step 3 ๐Ÿ˜„

You can use query selector to pin an element, but it'll take only the first element on the query.

Documentation

onPin - Function

Triggers a callback whenever the element is pinned.

Usage

new Pin('#pin', {
  onPin: function() {
    // code
  }
});

onUnpin - Function

Triggers a callback whenever the element is unpinned.

Usage

new Pin('#pin', {
  onUnpin: function() {
    // code
  }
});

onTouchBottom - Function

Triggers a callback whenever the element is touches the bottom of its parent container.

Usage

new Pin('#pin', {
  onTouchBottom: function() {
    // code
  }
});

stopOnBottom - Boolean | Default true

Stops the element when it touches the bottom of its parent container.

Usage

new Pin('#pin', {
  stopOnBottom: true
});

respectWindow - Boolean | Default true

If the height of the browser is smaller than the pinned element, it automatically gets unpinned

Usage

new Pin('#pin', {
  respectWindow: true
});

Methods

reload

Whenever you change the size of the pinned element, you should trigger this method to recalculate the positions of the element.

Usage

var pin = new Pin('#pin');

pin.reload();

destroy

If you want to disable the pin effect, use this method and it will unbind all events attached to window like scroll and resize.

Usage

var pin = new Pin('#pin');

pin.destroy();

Browser Support

IE Chrome Firefox Opera Safari
9 โœ” | Latest โœ” | Latest โœ” | Latest โœ” | Latest โœ” |

Maintainer

Contributing

  1. Fork Pin.js
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Send me a Pull Request
  5. That's it!

Please respect the indentation rules and code style.

License

Pin.js is released under the MIT License. See LICENSE file for details.

pin.js's People

Contributors

mauriciosoares avatar

Watchers

Fred avatar James Cloos avatar

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.