@ctrl/ngx-headroom

中文文档
5.0.0发布于 2021/11/29MITTypeScriptES Module近 30 天下载 1956

Headroom.js implementation in Angular

原始使用文档
文档目录6 节
  1. Dependencies
  2. Install
  3. Using Angular Headroom
  4. Overriding animation
  5. Inputs
  6. Outputs

ngx-headroom


npm circleci codecov

DEMO: https://ngx-headroom.netlify.com/

An Angular Component to hide/show your header on scroll. A port of of React Headroom by KyleAMathews which was based around headroom.js

Fixed headers are nice for persistent navigation but they can also get in the way by taking up valuable vertical screen space. Using this component lets you have your persistent navigation while preserving screen space when the navigation is not needed.

Dependencies

Latest version available for each version of Angular

ngx-headroomAngular
2.3.26.x 7.x
3.0.38.x 9.x
4.0.010.x 11.x
current>= 12.x

Install

npm install @ctrl/ngx-headroom

Using Angular Headroom

Import the module. Requires @angular/animations

// requires BrowserAnimationsModule
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
// import HeadroomModule
import { HeadroomModule } from '@ctrl/ngx-headroom';

Use the module

<ngx-headroom>
  <h1>You can put anything you'd like inside the Headroom Component</h1>
</ngx-headroom>

Overriding animation

The component is intended to be plug 'n play meaning it has sensible defaults for animating the header in and out. If you'd like to override the default animation.

Override animation defaults by passing your own values

<ngx-headroom duration="500" easing="ease-in-out">
  <h1>You can put anything you'd like inside the Headroom Component</h1>
</ngx-headroom>

Inputs

  • duration — Duration of animation in ms
  • easing — Easing of animation
  • upTolerance — scroll tolerance in px when scrolling up before component is pinned
  • downTolerance — scroll tolerance in px when scrolling down before component is pinned
  • disable — disable pinning and unpinning
  • wrapperStyle — pass styles for the wrapper div (this maintains the components vertical space at the top of the page).
  • parent — provide a custom 'parent' element for scroll events. parent should be a function which resolves to the desired element.
  • pinStart — height in px where the header should start and stop pinning. Useful when you have another element above Headroom component.

Outputs

  • pin - emitted when header is pinned
  • unpin - emitted when header is unpinned
  • unfix - emitted when header position is no longer fixed

GitHub @scttcper  ·  Twitter @scttcper

版本与发布记录

@ctrl/ngx-headroom 共发布 24 个版本,首次发布于 2017/12/17;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2021/11/294 年前
4.1.12021/11/294 年前
4.1.02021/11/294 年前
4.0.02020/12/145 年前
3.0.32020/10/016 年前
3.0.22020/10/016 年前

关于 @ctrl/ngx-headroom 的常见问题

@ctrl/ngx-headroom 是什么?

Headroom.js implementation in Angular

如何安装 @ctrl/ngx-headroom?

在项目目录运行 npm install @ctrl/ngx-headroom,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/animations(>=12.0.0)、@angular/core(>=12.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ctrl/ngx-headroom 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ctrl/ngx-headroom 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ctrl/ngx-headroom 可以商用吗?

@ctrl/ngx-headroom 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ctrl/ngx-headroom 的下载量有多少?

根据 npm 官方下载统计,@ctrl/ngx-headroom 在 2026/10/11 – 2026/11/09 这 30 天内被下载 1,956 次,日均约 65 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ctrl/ngx-headroom 还在维护吗?

最新版本 5.0.0 发布于 2021/11/29(4 年前);至今共发布 24 个版本,其中过去 12 个月发布了 0 个;首次发布于 2017/12/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。