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

fixedsticky

v0.1.0

Published

sticky吸顶组件

Downloads

13

Readme

fixedsticky

sticky组件,支持吸顶效果

如何使用

基本使用

实例方法为:

new lib.sticky(element, options)

或者把element放到options中做为一个属性:

new lib.sticky(options)

参数

  • element:一个DOM元素,或者是它的CSS选择器

  • top:(非必填)吸顶时元素距离视口顶部的高度,默认值为0

  • withinParent:(非必填,仅适用于Android)元素的sticky效果是否限制在父元素中,默认值为false

  • init:初始化实例

  • destroy:销毁实例

  • refresh:重置实例,如果withinParent设置为true,且父元素高度发生变化,请立即调用此方法

说明

在iOS上,由于scroll事件只有在滚动停止时才触发,所以使用原生sticky兼容性)实现完美的吸顶效果。

Android不支持原生sticky,使用监听scroll事件 + fixed和absolute + 一个占位元素模拟。

在使用lib.sticky组件时,为了兼容原生sticky的效果:

DOM结构必须严格遵守:

<div class="parent">
    <div class="sticky"></div>
</div>

对于sticky元素:

  • 最好为static元素
  • 若为定位元素
    • 只能设置z-index
    • 不要设置它的定位上下文
    • 不要设置它的top、bottom、left、right属性

对于父级元素:

  • 原生sticky元素仅在它父级容器内有效,超出容器范围则不再生效了。
    • 父级高度必须大于sticky元素的高度。
    • sticky元素的底部,不能和父级底部重叠。
  • 父级元素的overflow不能设置成auto、scroll、hidden。
  • sticky元素只能设置top值,设置bottom值无效。

更多参考资料:

其他:

  • 由于原生sticky元素在效果断点处没有提供事件,且iOS只有在滚动停止时才抛出scroll事件,想要在吸顶时刻添加一些其他行为在iOS上暂时无法实现。