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

stickto

v0.0.4

Published

make elements stick to top automatically(多dom自动吸顶库)

Downloads

9

Readme

stickto

简体中文

make elements stick to top automatically(多dom自动吸顶库)

Stickto is a small lib that helps DOM nodes stick to top of viewport automatically.

When you have more than one DOM needs to stick on top, stickto can help these DOM nodes auto switch with each other smoothly.

Demo transport

demo.gif

Install

npm install stickto

Import

this lib support UMD specification

  1. use script tag
<script src="stickto.js"/>
<script>
    // stick
    var stikcer = stickto.stick(/* DOM */)

    //unstick
    stickto.unstick(/* sticker or DOM */)
</script>
  1. use commonjs/es5
var stickto = require('stickto')

// stick
var stikcer = stickto.stick(/* DOM */)

//unstick
stickto.unstick(/* sticker or DOM */)
  1. use commonjs/es6
import {stick, unstick} from 'stickto'

// stick
var stikcer = stick(/* DOM */)

//unstick
unstick(/* sticker or DOM */)

API

stick

tells stickto there's a DOM node that needs to stick to viewport top automatically.

var stiker = stick(DOM[, options])

@params

  • DOM
    • type: HTMLElementNode
    • description: a DOM node that document.querySelector returned
    • optional: no

eg:

stick(document.querySelector('#foo'))
  • options
    • type: Object
    • description: customize z-index and/or css class name when sticker is sticking at top
    • optional: yes
    • default: {zIndex: 20, className: 'stickto-auto-generated-sticker'}
    • zIndex
      • type: Number/String
      • description: set z-index when sticker is sticking
      • optional: yes
      • default: 20
    • className
      • type: String
      • description: set css class name when sticker is sticking
      • optional: yes
      • default: stickto-auto-generated-sticker

eg:

stick(document.querySelector('#foo'), {
    zIndex: 1000,
    className: 'sticky',
})

@return

  • sticker
    • type: Sticker
    • description: an instance of Sticker

the stick method returns an instance of Sticker, when you don't want the sticker auto stick, it will be useful with the unstick method.

eg:

const stick = stick(document.querySelector('#foo'), {
    zIndex: 1000,
    className: 'sticky',
})

unstick

make a sticker unstick

unstick(sticker)

@params

  • sticker
    • type: Sticker/DOM
    • description: let a sticker unstick, the sticker was the stick method returned, or the DOM node that was used in stick method

eg:

recommand

const sticker = stick(document.querySelector('#foo'))
unstick(sticker)

or

const domNode = document.querySelector('#foo')
stick(domNode)
unstick(domNode)