Convert Figma logo to code with AI

filamentgroup logofixed-sticky

DEPRECATED: A position: sticky polyfill that works with filamentgroup/fixed-fixed for a safer position:fixed fallback.

1,486
153
1,486
26

Top Related Projects

Give your pages some headroom. Hide your header until you need it

This plugin is used to fix elements on the page (top, bottom, anywhere); however, it still allows the element to continue to move left or right with the horizontal scroll.

Fixed <thead>. Doesn't need any custom css/html. Does what position:sticky can't

Polyfill for CSS `position: sticky`

3,304

jQuery Plugin for Sticky Objects

Quick Overview

Fixed-sticky is a lightweight JavaScript plugin that provides a cross-browser solution for position:sticky. It allows elements to stick to the top of the viewport as the user scrolls, falling back to position:fixed for browsers that don't support sticky positioning natively.

Pros

  • Simple and lightweight implementation
  • Cross-browser compatibility, including fallback for older browsers
  • Works with both top and bottom positioning
  • Customizable through CSS classes and data attributes

Cons

  • Requires JavaScript to function, not a pure CSS solution
  • May have performance issues with a large number of sticky elements
  • Limited to vertical scrolling, doesn't support horizontal sticky positioning
  • Requires manual initialization for dynamically added elements

Code Examples

  1. Basic initialization:
$('.sticky').fixedsticky();

This code initializes fixed-sticky on all elements with the 'sticky' class.

  1. Setting custom options:
$('.custom-sticky').fixedsticky({
  top: 20,
  bottom: 20,
  zIndex: 100
});

This example shows how to set custom options for the sticky behavior, including top and bottom offsets and z-index.

  1. Destroying the plugin instance:
$('.sticky').fixedsticky('destroy');

This code removes the fixed-sticky functionality from the selected elements.

Getting Started

  1. Include the necessary files in your HTML:
<link rel="stylesheet" href="fixedsticky.css">
<script src="jquery.js"></script>
<script src="fixedsticky.js"></script>
  1. Add the fixedsticky class to the elements you want to make sticky:
<div class="fixedsticky">This element will stick to the top</div>
  1. Initialize fixed-sticky in your JavaScript:
$(document).ready(function() {
  $('.fixedsticky').fixedsticky();
});
  1. Optionally, customize the sticky behavior using CSS:
.fixedsticky {
  top: 0;
  /* Add any other custom styles */
}

Competitor Comparisons

Give your pages some headroom. Hide your header until you need it

Pros of headroom.js

  • More flexible and customizable, allowing for various behaviors beyond just sticking elements
  • Lightweight and dependency-free, making it easier to integrate into projects
  • Supports both vanilla JavaScript and as a jQuery plugin

Cons of headroom.js

  • Requires more setup and configuration compared to fixed-sticky's simpler approach
  • May have a steeper learning curve for developers new to the concept

Code Comparison

fixed-sticky:

$('.sticky').fixedsticky();

headroom.js:

var myElement = document.querySelector("header");
var headroom  = new Headroom(myElement);
headroom.init();

Summary

headroom.js offers more flexibility and customization options, making it suitable for complex header behaviors. It's lightweight and can be used with or without jQuery. However, it requires more initial setup and may be overkill for simple sticky elements.

fixed-sticky, on the other hand, provides a straightforward solution for creating sticky elements with minimal configuration. It's easier to implement for basic use cases but lacks the advanced features and customization options of headroom.js.

Choose headroom.js for more control over header behavior and advanced functionality, or fixed-sticky for quick and simple sticky elements with less configuration required.

This plugin is used to fix elements on the page (top, bottom, anywhere); however, it still allows the element to continue to move left or right with the horizontal scroll.

Pros of ScrollToFixed

  • More customizable with various options for controlling behavior
  • Supports both horizontal and vertical scrolling
  • Allows for dynamic recalculation of offsets

Cons of ScrollToFixed

  • Larger file size and potentially more complex implementation
  • May have performance issues with multiple fixed elements
  • Requires jQuery as a dependency

Code Comparison

ScrollToFixed:

$('.selector').scrollToFixed({
    marginTop: 10,
    limit: $('.footer').offset().top
});

fixed-sticky:

<div class="sticky">
    <div class="sticky-inner">Content</div>
</div>
.sticky { position: -webkit-sticky; position: sticky; top: 0; }

Key Differences

  1. Implementation: ScrollToFixed uses JavaScript for positioning, while fixed-sticky primarily relies on CSS with JavaScript fallbacks.
  2. Browser Support: fixed-sticky has better support for modern browsers using native position: sticky.
  3. Performance: fixed-sticky is generally more performant due to its CSS-first approach.
  4. Flexibility: ScrollToFixed offers more options for customization, while fixed-sticky aims for simplicity.
  5. Dependencies: ScrollToFixed requires jQuery, whereas fixed-sticky is standalone.

Both libraries aim to solve the problem of creating sticky elements, but they approach it differently. The choice between them depends on specific project requirements, browser support needs, and performance considerations.

Fixed <thead>. Doesn't need any custom css/html. Does what position:sticky can't

Pros of floatThead

  • More comprehensive solution for floating table headers
  • Supports complex table structures and nested tables
  • Offers more customization options and configuration settings

Cons of floatThead

  • Larger file size and potentially higher performance overhead
  • Steeper learning curve due to more complex API and configuration options
  • May require more setup and fine-tuning for optimal results

Code Comparison

fixed-sticky:

$('.sticky').fixedsticky();

floatThead:

$('table').floatThead({
  position: 'fixed',
  top: 50,
  scrollContainer: function($table){
    return $table.closest('.wrapper');
  }
});

Summary

fixed-sticky is a lightweight solution for creating sticky elements, including table headers. It's simple to implement but has limited functionality specific to tables. floatThead, on the other hand, is a more robust and feature-rich library focused exclusively on floating table headers. It offers greater flexibility and support for complex table structures but comes with a larger footprint and potentially more complex setup.

Choose fixed-sticky for simple sticky elements or basic table header needs, and floatThead for advanced table header floating requirements with more customization options.

Polyfill for CSS `position: sticky`

Pros of Stickyfill

  • More comprehensive polyfill for position: sticky, supporting a wider range of browsers
  • Actively maintained with recent updates and bug fixes
  • Smaller file size, potentially leading to better performance

Cons of Stickyfill

  • Requires more setup and configuration compared to Fixed-sticky
  • May have compatibility issues with some older browsers
  • Less straightforward implementation for simple use cases

Code Comparison

Fixed-sticky:

$(function() {
  $(".sticky").fixedsticky();
});

Stickyfill:

var elements = document.querySelectorAll('.sticky');
Stickyfill.add(elements);

Both libraries aim to provide sticky positioning functionality, but they differ in their approach and implementation. Fixed-sticky offers a simpler, jQuery-based solution that's easy to implement for basic use cases. Stickyfill, on the other hand, provides a more comprehensive polyfill for position: sticky, supporting a wider range of browsers and scenarios.

Fixed-sticky is lightweight and straightforward, making it a good choice for projects with simple sticky requirements. Stickyfill offers more features and better browser support, but it may require more setup and configuration.

When choosing between the two, consider your project's specific needs, browser support requirements, and the level of sticky functionality you need to implement.

3,304

jQuery Plugin for Sticky Objects

Pros of sticky

  • Lightweight and simple implementation
  • No dependencies, pure JavaScript solution
  • Easy to customize and integrate into existing projects

Cons of sticky

  • Less feature-rich compared to fixed-sticky
  • May require more manual configuration for complex use cases
  • Limited browser support for older versions

Code Comparison

fixed-sticky:

$(function() {
  $(".sticky").fixedsticky();
});

sticky:

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

Key Differences

  • fixed-sticky is a jQuery plugin, while sticky is a standalone JavaScript library
  • fixed-sticky offers more advanced features like handling multiple sticky elements and responsive behavior
  • sticky provides a simpler API but may require more custom code for complex scenarios

Use Cases

  • Choose fixed-sticky for projects with jQuery and need for advanced sticky functionality
  • Opt for sticky in lightweight projects or when avoiding jQuery dependencies

Community and Maintenance

  • fixed-sticky has more stars and contributors on GitHub
  • sticky has fewer recent updates but remains a popular choice for its simplicity

Both libraries offer effective solutions for creating sticky elements, with the choice depending on project requirements and preferences for simplicity versus feature richness.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Fixed-sticky

🚨🚨 This plugin is Deprecated 🚨🚨

In our own designs we use sticky sparingly and as an enhancement, which means that fallback positioning behavior is acceptable. With native browser support for position: sticky expanding, we must weigh the diminishing cross-section of browsers that require this polyfill against this plugin’s own maintenance costs. Therefore, we’ve decided that now is the right time to retire fixed-sticky. The previous documentation can be found at v0.1.7. NPM will report a deprecation warning. If you want to maintain a fork of this package, send me a message (@zachleat on Twitter) and I’ll add a link to it below. Thank you!

Filament Group

  • ©2013 @zachleat, Filament Group
  • MIT license

Great alternatives

Native position: sticky

The most overlooked thing about position: sticky is that sticky elements are constrained to the dimensions of their parent elements. This means if a sticky element is inside of a parent container that is the same dimensions as itself, the element will not stick.

Here’s an example of what a sticky element with CSS top: 20px behaves like:

Scrolling down. The blue border represents the dimensions of the parent container element. If the element’s top is greater than 20px to the top of the viewport, the element is not sticky.

Scrolling down. When the element’s top is less than 20px to the top of the viewport, the element is sticky.

Here’s an example of what a sticky element with CSS bottom: 20px behaves like:

Scrolling up. Not sticky.

Scrolling up. Sticky.

Demos

Native position: sticky Caveats

  • Any non-default value (not visible) for overflow, overflow-x, or overflow-y on the parent element will disable position: sticky (via @davatron5000).
  • iOS (and Chrome) do not support position: sticky; with display: inline-block;.
  • This plugin (and Chrome’s implementation) does not support use with thead and tfoot.
  • Native sticky anchors to parent elements using their own overflow. This means scrolling the element fixes the sticky element to the parent dimensions. This plugin does not support overflow on parent elements.

NPM DownloadsLast 30 Days