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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@tanzhenxing/zx-anchor

v1.0.4

Published

锚点组件,用于快速定位页面内容

Readme

ZxAnchor 锚点组件

通过锚点,您可以很快找到当前页面上信息内容的位置。

基础用法

最简单的用法。

<template>
  <zx-anchor :offset="70">
    <zx-anchor-link href="#part1">第一部分</zx-anchor-link>
    <zx-anchor-link href="#part2">第二部分</zx-anchor-link>
    <zx-anchor-link href="#part3">
      第三部分
      <template #sub-link>
        <zx-anchor-link href="#part3-1">子部分1</zx-anchor-link>
        <zx-anchor-link href="#part3-2">子部分2</zx-anchor-link>
      </template>
    </zx-anchor-link>
  </zx-anchor>
</template>

水平模式

水平排列的锚点(水平模式不支持子链接)

<template>
  <zx-anchor :offset="70" direction="horizontal">
    <zx-anchor-link href="#part1">第一部分</zx-anchor-link>
    <zx-anchor-link href="#part2">第二部分</zx-anchor-link>
    <zx-anchor-link href="#part3">第三部分</zx-anchor-link>
  </zx-anchor>
</template>

自定义滚动区域

自定义滚动区域,使用 offset 属性可以设置锚点滚动偏移。

<template>
  <div>
    <div ref="containerRef" style="height: 300px; overflow-y: auto">
      <div id="part1" style="height: 300px; background: rgba(255, 0, 0, 0.02)">part1</div>
      <div id="part2" style="height: 300px; background: rgba(0, 255, 0, 0.02)">part2</div>
      <div id="part3" style="height: 300px; background: rgba(0, 0, 255, 0.02)">part3</div>
    </div>
    <zx-anchor :container="containerRef" :offset="30" @click="handleClick">
      <zx-anchor-link href="#part1" title="part1" />
      <zx-anchor-link href="#part2" title="part2" />
      <zx-anchor-link href="#part3" title="part3" />
    </zx-anchor>
  </div>
</template>

<script>
export default {
  methods: {
    handleClick(e) {
      // 阻止浏览器默认行为
      e.preventDefault()
    }
  }
}
</script>

下划线类型

设置 type="underline" 更改为下划线类型

<template>
  <zx-anchor type="underline" :offset="70">
    <zx-anchor-link href="#part1">第一部分</zx-anchor-link>
    <zx-anchor-link href="#part2">第二部分</zx-anchor-link>
    <zx-anchor-link href="#part3">第三部分</zx-anchor-link>
  </zx-anchor>
</template>

监听锚点变化

使用 change 事件可以监听当前活动锚点的变化

<template>
  <zx-anchor :offset="70" @change="handleChange">
    <zx-anchor-link href="#part1">第一部分</zx-anchor-link>
    <zx-anchor-link href="#part2">第二部分</zx-anchor-link>
    <zx-anchor-link href="#part3">第三部分</zx-anchor-link>
  </zx-anchor>
</template>

<script>
export default {
  methods: {
    handleChange(href) {
      console.log(`锚点变化: ${href}`)
    }
  }
}
</script>

属性

ZxAnchor 属性

| 属性 | 说明 | 类型 | 默认值 | | --------------- | ------------------- | ----------------------- | ---------- | | container | 滚动的容器 | string | HTMLElement | Window | | offset | 设置锚点滚动的偏移量 | number | 0 | | bound | 触发锚点的元素的位置偏移量 | number | 15 | | duration | 设置容器滚动持续时间,单位为毫秒 | number | 300 | | marker | 是否显示标记 | boolean | true | | type | 设置锚点类型 | 'default' | 'underline'| 'default' | | direction | 设置锚点方向 | 'vertical' | 'horizontal' | 'vertical' | | selectScrollTop | 滚动时,链接是否选中位于顶部 | boolean | false |

ZxAnchor 事件

| 事件名 | 说明 | 类型 | | ------- | ------------------- | --------------------- | | change | 锚点链接变化时的回调 | Function(href: string) | | click | 当用户点击链接时触发 | Function(event: Event) |

ZxAnchor 方法

| 名称 | 说明 | 类型 | | --------- | ---------------- | --------------------- | | scrollTo | 手动滚动到特定位置 | Function(href: string) |

ZxAnchorLink 属性

| 属性 | 说明 | 类型 | 默认值 | | ------- | ---------- | -------- | ------ | | title | 链接的文本内容 | string | '' | | href | 链接的地址 | string | '#' |

ZxAnchorLink 插槽

| 名称 | 说明 | | --------- | ------------ | | default | 链接的内容 | | sub-link | 子链接的插槽 |