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

@autofe/sticky

v0.1.0

Published

A Sticky library based on jQuery

Downloads

2

Readme

Sticky

由于吸顶的实现采用的是 position: fixed,所以需要自己在样式里手动设置 width

Usage

通过脚本来初始化,如果不配置参数,默认开启吸顶功能。

$('.sticky-demo').sticky();

配置吸顶时到顶部的距离为 10px

$('.sticky-demo').sticky({
  offset: 10 // 开启吸顶,吸顶时到顶部距离为 10px
});

// or

$('.sticky-demo').sticky({
  offsetTop: 10 // 开启吸顶,吸顶时到顶部距离为 10px
});

可以通过配置开启吸底效果

$('.sticky-demo').sticky({
  offsetBottom: 10 // 开启吸顶,吸顶时到顶部距离为 10px
});

还可以通过 HTML data 属性的方式配置参数

<div class="sticky-demo">
  吸顶,到顶部距离为 0
</div>
<div class="sticky-demo" data-offset="10">
  吸顶,到顶部距离为 10
</div>
<div class="sticky-demo" data-offset-top="10">
  吸顶,到顶部距离为 10
</div>
<div class="sticky-demo" data-offset-bottom="10">
  吸底,到底部距离为 10
</div>
<div class="sticky-demo" data-offset-top="10" data-offset-bottom="20">
  吸顶和吸底效果同时开启
</div>

Options

参数可以通过 data attributes 或者 JavaScript 两种方式来配置.

Name | Type | Default | Description ---- | ---- | ------- | ----------- offset | number or object | {top:0} | 用来设置吸顶和吸底的距离,格式 {top: 10, bottom: 20} ,其中 topbottom 还可以是函数 offsetTop | number or function | 无 | 设置吸顶距离 offsetBottom | number or function | 无 | 设置吸底距离

Methods

.sticky(options)

初始化

$('#stickyDemo').sticky();

Events

Event Type | Description ---------- | ----------- top.fe.sticky | 进入吸顶状态时触发 bottom.fe.sticky | 进入吸底状态时触发 off.fe.sticky | 从吸顶或者吸底状态退出时触发

$('.nav-example')
  .on('top.fe.sticky', function() {
    $(this).html('<p>吸顶状态</p>')
  })
  .on('bottom.fe.sticky', function() {
    $(this).html('<p>吸底状态</p>')
  })
  .on('off.fe.sticky', function() {
    $(this).html('<p>常规状态</p>')
  });

End

Thanks to Bootstrap