Giter Site home page Giter Site logo

inspireling / hc-sticky Goto Github PK

View Code? Open in Web Editor NEW

This project forked from somewebmedia/hc-sticky

0.0 1.0 0.0 303 KB

Dependency free javascript library that makes any element on your page visible while you scroll.

Home Page: https://somewebmedia.github.io/hc-sticky/

License: MIT License

JavaScript 100.00%

hc-sticky's Introduction

HC-Sticky

Dependency free javascript library that makes any element on your page visible while you scroll. Check out the demos.

Quick start

Install

This package can be installed with:

  • npm: npm install --save hc-sticky
  • bower: bower install --save hc-sticky

Or download the latest release.

Load

Static HTML

<script src="/path_to/hc-sticky.js"></script>

Browserify

In the script, including HC-Sticky will usually look like this:

const hcSticky = require('hc-sticky');

Usage

Be sure to call HC-Sticky once your element is available in the DOM.

Vanilla JS

var Sticky = new hcSticky('#element', {
  stickTo: '#content'
});

jQuery

jQuery(document).ready(function($) {
  $('#element').hcSticky({
    stickTo: '#content'
  });
});

Options

HC Sticky has a wide range of options you can set to have a full controll over the sticky elements.

Property Default Type Description
top 0 int The distance from the top of the Window at which to trigger HC-Sticky.
bottom 0 int The distance from the bottom of the Window at which to attach HC-Sticky.
innerTop 0 int The distance from the top inside of the sticky element at which to trigger HC-Sticky.
innerSticker null string / element object Element inside of the sticky element at which to attach HC-Sticky. This has higher priority than innerTop option.
bottomEnd 0 int The distance from the bottom of the referring element at which to stop HC-Sticky.
stickTo null (parent element) string / element object Element that represents the reference for height instead of height of the container.
followScroll true boolean When set to false, sticky content will not move with the page if it is bigger than Window.
stickyClass 'sticky' string HTML class that will be applied to sticky element while it is attached.
responsive null object Object containing responsive breakpoints, on which you can tell HC Sticky what to do.
mobileFirst false boolean Direction of the responsive queries.
disable false boolean Disable the plugin. Usualy used with responsive object.
onStart null function Callback function fired when the element becomes attached.
onStop null function Callback function fired when the element stops floating.
onBeforeResize null function Callback function fired before sticky has been resized (happens after Window resize and before sticky reinit).
onResize null function Callback function fired after sticky has been resized (happens after Window resize and sticky reinit).
resizeDebounce 100 int Limit the rate at which the HC Sticky can fire on window resize.

More on how to use the responsive object here.

Methods

Methods are used to control the plugin after initialization.

Method Accepts Description
options string Returns current settings, or a specific setting if you specify it.
update object Updates the settings with the new ones.
refresh N/A Recalculates sticky size and position. Useful after altering DOM elements inside sticky.
detach N/A Detaches the HC-Sticky from element, preventing it from running.
attach N/A Attaches the HC-Sticky back to the element.
destroy N/A Completely destroys HC-Sticky and reverts element to original state.

Vanilla JS

var Sticky = new hcSticky('#element', {
  stickTo: '#content'
});

Sticky.update({
  top: 20
});

jQuery

var $sticky = $('#element');

$sticky.hcSticky({
  stickTo: '#content'
});

$sticky.hcSticky('update', {
  top: 20
});

Dev Building

This package comes with Gulp. The following tasks are available:

  • default compiles the JS into /dist and builds the Demos into demo/build.
  • watch watches source JS and Demo files and builds them automatically whenever you save.

You can pass a --dev command if you don't want the compiled JS to be minified.

License

The code and the documentation are released under the MIT License.

hc-sticky's People

Contributors

somewebmedia avatar alexcason avatar kusmierz avatar almo7aya avatar dailyraisin avatar

Watchers

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.