npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fixiejs

v2.0.2

Published

Utility to fix elements vertically as the page scrolls. Configurable, reusable.

Downloads

8

Readme

fixie

Fix elements vertically as the page scrolls down. Configurable, reusable. "Pin" the given element to the top of the page on vertical scroll. Also know as "conditional fixed placement".

No dependencies. Useful if you're not using React or something like that.

The main feature is that this supports different strategies. All the code I saw took a single approach, and it may not work for your markup or page length. This tool allows you to try different techniques, or event switch in different situations.

If you're looking for the jQuery plugin, use an earlier, < 2.0 version. The current one does not require jQuery. (There's no reason it won't work at the same time, though.)

If you want jQuery (or some other feature), let me know. I think I'm the only one using this, so I am not implementing backward compatibility unless asked.

Demo

> git clone ...
> yarn install
> open demo.html

http://ndpsoftware.com/fixie/demo.html

Usage

Webpack or similar

> yarn add fixiejs
  // my-file.js
  import { fixie } from 'fixiejs'
  const el = document.getElementById(...) or $('#menu')[0]
  fixie(el);   // use defaults
  fixie(el, { topMargin: '20px' }); // see Options below

Direct inclusion on web pages

This is not recommended, but if you want, dist/fixie.min.js can be directly included on a web page. Just grab it, similar to how the demo page does.

Options

Accepts an options object, which may contain (with defaults):

  • strategy: fixed Choose an implementation. See below.
  • topMargin: 0 Specifies how close to the top to pin the element. Usually you want elements pinned to the top, but sometimes they need to be below some other element, such as a fixed header.
  • pinnedClass: _pinnedToTop Any css class to add on to the element when it is pinned.
  • pinnedBodyClass: undefined A CSS class to add to the body element when this element is pinned. Default is to add no class.
  • throttle: 30 (ms) How often to adjust position of element
  • pinSlop: 0 Usually when the user scrolls an element to the top of the page, it becomes "fixed". This "slop" value allows it to go past, or become fixed before it's actually at the top.

Strategies

There are various strategies available:

  • relative: simply make the element positioned relative and adjust position whenever the user scrolls. Works with simple elements
  • relativeWithHiding: same as above, except fades out and shows elements as they move
  • fixed: makes the element fixed positioned. This is very performant, but it has a couple drawbacks. First, you must take care that when the element becomes "fixed", that it maintains its natural width. This is better done with your CSS than fixie itself, so that the pinned element can respond well to browser resizing. Often this is only a "width: 100%" statement.

Development

Uses minimal tooling. See package.json for relevant stuff.

Rollup is used to build minified web-ready file, but otherwise not needed.

License

Copyright (c) 2013-2021 NDP Software. Andrew J. Peterson MIT License; see LICENSE.txt

History

  • 2021-07-29 Convert to Typescript
  • Bug fix: relativeWithHiding strategy resets opacity to inherit after element is made visible, so that fixed items can have any opacity applied with CSS.
  • 1.0.1: add bower file
  • 1.0.0: first release

References

  • http://github.com/ndp/jsutils for tests
  • http://www.gregjopa.com/2011/07/conditional-fixed-positioning-with-jquery/