# @uvarov.frontend/vanilla-sticky

> Vanilla JS sticky block without using extra packages.

Latest version **1.0.0** (published 2022-06-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @uvarov.frontend/vanilla-sticky
pnpm add @uvarov.frontend/vanilla-sticky
yarn add @uvarov.frontend/vanilla-sticky
bun add @uvarov.frontend/vanilla-sticky
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-06-14 |
| First published | 2022-05-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Yuri Uvarov |
| Maintainers | uvarov.frontend |
| Keywords | sticky, js, javascript, vanilla, vanilla-js |

## Links

- npm: https://www.npmjs.com/package/@uvarov.frontend/vanilla-sticky
- Repository: https://github.com/uvarov-frontend/vanilla-sticky
- Homepage: https://vanilla-sticky.frontend.uvarov.tech/
- Issues: https://github.com/uvarov-frontend/vanilla-sticky/issues
- npm.io page: https://npm.io/package/@uvarov.frontend/vanilla-sticky

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-06-14
- 0.0.9 — 2022-06-14
- 0.0.8 — 2022-05-12
- 0.0.7 — 2022-05-12
- 0.0.6 — 2022-05-12
- 0.0.5 — 2022-05-12

## README

# Vanilla JS Sticky v1.0.0

Vanilla JS sticky block without using extra packages. [DEMO](https://vanilla-sticky.frontend.uvarov.tech/)

## Initialize

Get vanilla-sticky in one of the following ways:

### NPM

```sh
npm install @uvarov.frontend/vanilla-sticky
```

Then import it in your javascript file

```js
import VanillaSticky from '@uvarov.frontend/vanilla-sticky';
```

### or Script tag

It’s possible to manually include the necessary `<script>` tags in the end body of your HTML page and then initialize a calendar via browser globals.

CDN

```html
<script src="https://cdn.jsdelivr.net/npm/@uvarov.frontend/vanilla-sticky@1.0.0/vanilla-sticky.min.js"></script>
```

or locally

```html
<script src="./js/vanilla-sticky.min.js"></script>
```

## API

The `HTMLElement` option is mandatory, all other options are optional.

| Name | Default | Description |
| ---- | :-----: | ----------- |
| HTMLElement | — | DOM object |
| position | auto | Specifies which edge the block will stick to. Available options: 'auto', 'top', 'bottom'. |
| stretch | true | Stretch the content to the full height of the screen minus the indents if the content is less than the height of the screen. |
| resize | true | Recalculate the height of the content and its location each time the screen height changes. |
| indents.top | 0 | Specify the top indents after which the block will stick. |
| indents.bottom | 0 | Specify the bottom indents after which the block will stick. |
| window.min | null | The minimum screen width after which the module stops working. |
| window.max | null | The maximum screen width after which the module stops working. |

## Usage example

```js
const sidebar = new VanillaSticky({
  HTMLElement: document.querySelector('.sidebar'),
  position: 'bottom',
  stretch: false,
  resize: true,
  indents: {
   top: 70,
   bottom: 10,
  },
  window: {
   min: 1200,
   max: null,
  },
 });

 sidebar.init();
```

Change settings and update:

```js
sidebar.position = 'top';
sidebar.stretch = true;
sidebar.indents.top = 30;
sidebar.indents.bottom = 20;

sidebar.update();
```

## License

MIT License

## Author

Yuri Uvarov (*uvarov.frontend@gmail.com*)

---
_Source: https://npm.io/package/@uvarov.frontend/vanilla-sticky · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
