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

sticky-polyfill

v1.0.2

Published

polyfill for position:sticky

Downloads

1

Readme

介绍Stick

position: sticky是新增的css属性,粘性定位可以被认为是相对定位和固定定位的混合。元素在跨越特定阈值前为相对定位,之后为固定定位。

但是并不是所有浏览器都支持position: sticky

所以我做了一个sticky-polyfill处理。

思路

  1. 获取元素初始化时候的offsetTop,并存储在元素的dataset中
  2. 监听滚动条事件,并使用节流方式处理滚动事件处理器
  3. 在事件处理器里,获取浏览器的纵轴的滚动偏移量——window.pageYOffset,然后跟元素的纵轴偏移量作比较,判断是否需要对元素做position: fixed处理,或者还原positon

因为需要把元素设置为 position: fixed;所以元素的width和height需要制定确切的值

API

该库仅对外提供一个接口:

/**
* position: sticky的polyfill
* 推荐在文档加载完成之后(‘DOMContentLoaded’事件)调用
* @param {String} selectors 选择器
* @param {String} top 距离顶部的偏移量
*/
function sticky(selectors, top = 0)

使用NPM安装

npm i sticky-polyfill --save

项目地址

GitHub地址

演示

可以在CodePen上看到效果。