All Projects → vursen → Floatsidebar.js

vursen / Floatsidebar.js

Licence: mit
Lightweight (2kb gzipped), zero-dependency javascript library for making float sidebars based on the finite state machine

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Floatsidebar.js

UnityHFSM
A simple yet powerful class based hierarchical finite state machine for Unity3D
Stars: ✭ 243 (+333.93%)
Mutual labels:  lightweight, fsm, finite-state-machine
Vscode Yarn
VSCode extension to manage yarn commands
Stars: ✭ 18 (-67.86%)
Mutual labels:  npm, yarn
Gitpkg
use a sub directory of a github repo as yarn / npm dependency directly
Stars: ✭ 54 (-3.57%)
Mutual labels:  npm, yarn
Npm Script Naming Ideas
Ideas for naming npm scripts
Stars: ✭ 12 (-78.57%)
Mutual labels:  npm, yarn
Libfsm
DFA regular expression library & friends
Stars: ✭ 512 (+814.29%)
Mutual labels:  finite-state-machine, fsm
Stateless4j
Lightweight Java State Machine
Stars: ✭ 658 (+1075%)
Mutual labels:  finite-state-machine, fsm
Yarn Package Boilerplate
An Yarn package with babel, jest, flow, prettier and more
Stars: ✭ 10 (-82.14%)
Mutual labels:  npm, yarn
Salus
Security scanner coordinator
Stars: ✭ 441 (+687.5%)
Mutual labels:  npm, yarn
Magic
CSS3 Animations with special effects
Stars: ✭ 7,253 (+12851.79%)
Mutual labels:  npm, yarn
Typac
install npm packages along with corresponding typings
Stars: ✭ 29 (-48.21%)
Mutual labels:  npm, yarn
Mailgo
💌 mailgo, a new concept of mailto and tel links
Stars: ✭ 978 (+1646.43%)
Mutual labels:  npm, yarn
Synp
Convert yarn.lock to package-lock.json and vice versa
Stars: ✭ 510 (+810.71%)
Mutual labels:  npm, yarn
Npm Gui
Graphic tool for managing javascript project dependencies - in a friendly way.
Stars: ✭ 454 (+710.71%)
Mutual labels:  npm, yarn
Np
A better `npm publish`
Stars: ✭ 6,401 (+11330.36%)
Mutual labels:  npm, yarn
Fsm As Promised
A finite state machine library using ES6 promises
Stars: ✭ 446 (+696.43%)
Mutual labels:  finite-state-machine, fsm
Install Self Peers
Stars: ✭ 26 (-53.57%)
Mutual labels:  npm, yarn
Tsdx
Zero-config CLI for TypeScript package development
Stars: ✭ 9,010 (+15989.29%)
Mutual labels:  npm, yarn
Benchmarks Of Javascript Package Managers
Benchmarks of JavaScript Package Managers
Stars: ✭ 388 (+592.86%)
Mutual labels:  npm, yarn
Lockfile Lint
Lint an npm or yarn lockfile to analyze and detect security issues
Stars: ✭ 411 (+633.93%)
Mutual labels:  npm, yarn
Yarpm
CLI tool to run npm scripts with either npm or yarn, depending on how it was started
Stars: ✭ 13 (-76.79%)
Mutual labels:  npm, yarn

FloatSidebar.js

NPM version

Lightweight (2kb gzipped), zero-dependency javascript library for making float sidebars based on the finite state machine

Demo

This library based on the finite state machine pattern. It allowed to get a much more simple and reliable solution.

You can read more about this approache in the article on medium (in russian)

Install

npm install float-sidebar

or

yarn add float-sidebar

or

<script src="./path/to/float-sidebar.min.js"></script>

Usage

<div class="wrapper">
  <div class="content">
    <!-- Content -->
  </div>

  <div class="sidebar">
    <div class="sidebar__inner">
      <!-- Sidebar content -->
    </div>
  </div>
</div>
.wrapper {
  display: flex;
  /*
    Required.
    It will prevent the infinite growth of the sidebar height if you are using the library with 'infinite scroll'
  */
  align-items: flex-start;
}

.sidebar {
  /* Required */
  position: relative;

  /* Required. The sidebar element must have a fixed width */
  width: 220px;
}
import FloatSidebar from 'float-sidebar';

const sidebar  = document.querySelector('.sidebar');
const relative = document.querySelector('.content');

const floatSidebar = FloatSidebar({
  sidebar,
  relative,
  topSpacing: 20,
  bottomSpacing: 20
});

// ...

floatSidebar.forceUpdate();

// ...

floatSidebar.destroy();

Options

sidebar

Type: Element
Required

Sidebar element

relative

Type: Element
Required

Sidebar relative element, e.g. main content

viewport

Type: Element
Defaults: window

Viewport element

sidebarInner

Type: Element
Defaults: first element child of sidebar element

Sidebar inner element

topSpacing

Type: Integer
Defaults: 0

Viewport top spacing when sidebar fixed

bottomSpacing

Type: Integer
Defaults: 0

Viewport bottom spacing when sidebar fixed

Instance API

forceUpdate()

Force recalculate and update sidebar position

destroy()

Destroy plugin (doesn't delete DOM elements)

License

FloatSidebar.js is released under the MIT license.

Author Sergey Vinogradov

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].