Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

sticky-js

> 编程语言
Open source

Library for sticky elements written in vanilla javascript

725 stars0 likes1 views
WebsiteGitHub

About

Library for sticky elements written in vanilla javascript

sticky-js

Sticky-js is a library for sticky elements written in vanilla javascript. With this library you can easily set sticky elements on your website. It's also responsive.

DEMO

Features

  • Written in vanilla javascript, no dependencies needed
  • Lightweight (minified: ~7.0kb, gzipped: ~1.9kb)
  • It can be sticky to the entire page or to selected parent container
  • No additional CSS needed

Install

bash
npm install sticky-js
bower install sticky.js

Usage

Simply include

xml

Then have element

xml

Initialize in javascript

javascript
var sticky = new Sticky('.selector');

Syntax

javascript
new Sticky([selector:string], [global options:object])

CommonJS

javascript
var Sticky = require('sticky-js');

var sticky = new Sticky('.selector');

Examples

Multiple sticky elements with data-sticky-container and options

xml

  

  

Methods

Update sticky, e.g. when parent container (data-sticky-container) change height

javascript
var sticky = new Sticky('.sticky');

// and when parent change height..
sticky.update();

Destroy sticky element

javascript
var sticky = new Sticky('.sticky');

sticky.destroy();

Available options

Option Type Default Description
data-sticky-wrap boolean false When it's true sticky element is wrapped in `` which has sticky element dimensions. Prevents content from "jumping".
data-margin-top number 0 Margin between page and sticky element when scrolled
data-sticky-for number 0 Breakpoint which when is bigger than viewport width, sticky is activated and when is smaller, then sticky is destroyed
data-sticky-class string null Class added to sticky element when it is stuck

Development

Clone this repository and run

javascript
npm start

Browser Compatibility

Library is using ECMAScript 5 features.

  • IE 9+
  • Chrome 23+
  • Firefox 21+
  • Safari 6+
  • Opera 15+

If you need this library working with older browsers you should use ECMAScript 5 polyfill.

Full support


Website

https://rgalus.github.io/sticky-js/

License

MIT License

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScriptbrowserjavascriptstickysticky-elements

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言