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

@w11k/angular-sticky-things

v1.10.1

Published

[![npm version](https://img.shields.io/npm/v/@w11k/angular-sticky-things.svg?style=flat-square)](https://www.npmjs.com/package/@w11k/angular-sticky-things)

Downloads

10,512

Readme

npm version

Angular Sticky Things

An Angular directive for making things sticky when the user scrolls (for Angular 2+) with no jQuery Dependency.

See the demo here.

Sure! Here's the compatibility chart formatted as a Markdown table:

Compatibility Chart

| Angular Version | Package Version | |-----------------|-----------------| | 11-12 | 1.4.0 | | 13 | 1.5.0 | | 14 | 1.6.0 | | 15 | 1.7.0 | | 16 | 1.8.1 | | 17 | 1.9.2 | | 18 | 1.10.1 |

Requirements

  • Angular (requires Angular 11.x or higher)
  • Supports all major browsers and IE11 and up (lower versions might not be supported)

Features:

  • Stick all the things!
  • Super smooth!
  • Tested in real world projects
  • Support for Angular Universal
  • Prevents page-jumping when switching to sticky mode
  • No jQuery or other dependencies - pure Angular solution

Installation

with npm:

npm install @w11k/angular-sticky-things

with yarn:

yarn add @w11k/angular-sticky-things

Now import the AngularStickyThingsModule in the corresponding Module

import {AngularStickyThingsModule} from '@w11k/angular-sticky-things';

@NgModule({
  declarations: [
  ],
  imports: [
    AngularStickyThingsModule,
  ],
  providers: [],
})
export class SomeModule { }

Usage:

<div #spacer></div>
<div stickyThing [spacer]="spacer">
  I am sticky!
</div>

Boundary Elements

If a boundary element is defined, the sticky element scrolls only within the height of the boundary element and then stops. This is useful if you have multiple sticky elements since it prevents stacking. You can take a look at the examples.

<div #boundary style="height:1000px;">
  <div #spacer></div>
  <div stickyThing [spacer]="spacer" [boundary]="boundary">
    I am sticky but only inside #boundary!
  </div>
</div>

Hint: The boundary feature is still in beta - position errors might occur!

Spacer

The spacer is not required but prevents a page jump when the sticky effect steps in.

Enable

An enable (default true) input can be used to dynamically activate or deactivate the sticky directive (e.g. to have a sticky navbar only in certain conditions). You can take a look at the examples.

<div #spacer></div>
<div stickyThing [spacer]="spacer" [enable]="enableSticky">
  I can become sticky only when enableSticky is true!
</div>

Margins

A marginTop (default 0) input can be used to add some top spacing to the sticky element, in case you don't want it to stick right at the top. It expects the number of pixels you want to use for the space. You can take a look at the examples. Accordingly, marginBottom is available.

<div #boundary style="height:1000px;">
  <div #spacer></div>
  <div stickyThing [spacer]="spacer" marginTop="30">
    I leave 30px of space to the top when I'm sticky!
  </div>
</div>

Event Outputs

<div #boundary style="height:1000px;">
  <div #spacer></div>
  <div stickyThing (stickyPosition)="consoleLog($event)" (stickyStatus)="consoleLog($event)" marginTop="30" marginBottom="50">
    I leave 30px of space to the top when I'm sticky!
  </div>
</div>

Example Output:

[Log] stickyPositon - {offsetY: 786, bottomBoundary: 1406.9999389648438, upperScreenEdgeAt: 75, marginBottom: "50", marginTop: "30"}
[Log] stickyStatus - {isSticky: false, reachedUpperEdge: true, reachedLowerEdge: false}

Scroll in Container

Per default Sticky Things expects your body to be the element that scrolls. However, if Sticky Things is used in an overflow-container, that container must be made known to the directive.

This is best done with a query selector. If a string is provided it will be called with document.querySelector. Instead an HTML element (nativeElement) can be provided as well.

Note: In a scrollable container boundary, spacer and margins don't work.

<div class="scrollable-container">
  <p>I'm special, since my content scrolls and not the body.</p>
  <p>...</p>
  <div stickyThing [scrollContainer]="'.scrollable-container'">Sticky</div>
</div>
.scrollable-container {
  height: 300px;
  margin: 3em auto;
  overflow: scroll;
}

Patron

❤️ W11K - The Web Engineers

❤️ theCodeCampus - Trainings for Angular and TypeScript