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/tab

v0.1.2

Published

A Tab library based on jQuery

Downloads

5

Readme

Tab

TODO

  • 滑块功能
  • 自动切换
  • 动态添加 Tab ?

Usage

无需写任何 JavaScript 来激活 Tab , 只需在元素上简单的指定 data-toggle="tab"data-target="#ID"

一般来说,在写 Tab 的 DOM 结构式, 需要先手动的指定当前打开的 Tab 标签, 这可以通过指定样式类 active 来实现.

<ul class="nav">
  <li><a href="javascript:void(0);" class="active" data-toggle="tab" data-target="#tab1-1">市场分析</a></li>
  <li><a href="javascript:void(0);" data-toggle="tab" data-target="#tab1-2">用户调研</a></li>
  <li><a href="javascript:void(0);" data-toggle="tab" data-target="#tab1-3">美图欣赏</a></li>
</ul>
<div class="content">
  <div id="tab1-1" class="content-item active">...市场分析内容...</div>
  <div id="tab1-2" class="content-item">...用户调研内容...</div>
  <div id="tab1-3" class="content-item">...美图欣赏内容...</div>
</div>

关于 DOM 结构

默认使用 <ul> 来包含一组标签, 你还可以通过 data-tab-list 来指定一组标签的父元素. 至于标签面板, 要求所有面板属于兄弟节点关系.

Options

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

Name | Type | Default | Description ---- | ---- | ------- | ----------- trigger | string | 'click' | 标签触发方式 click|hover. delay | number | 150 | 标签的触发延时时长,当 triggerhover 时才有效. activeClass | string | 'active' | 标签激活状态样式类. tabList | string | '[data-tab-list]' | 标签父容器

Methods

.tab(options)

初始化 Tab 控件, 可以接受参数进行配置. 注意, 需要将一组 Tab 标签都初始化, 比如下面的代码中的 $('.video-list a[data-tab]') 代表了一组 Tab 标签.

$('.video-list a[data-tab]').tab({
  trigger: 'hover',
  delay: 50
});

.tab('show')

激活并显示某个 Tab 标签, 同时关闭同一组的其他标签.

$('.nav li a:first').tab('show'); // 选择第一个标签
$('.nav li a:last').tab('show'); // 选择最后一个标签
$('.nav li:eq(2) a').tab('show'); // 选择第三个标签

Event

Event Type | Description ---------- | ----------- show.fe.tab | 事件在标签显示时触发. 使用 event.targetevent.relatedTarget 分别来定位当前活动标签和上一个选择的标签(如果有的话). shown.fe.tab | 事件在标签显示完毕时触发. 使用 event.targetevent.relatedTarget 分别来定位当前活动标签和上一个选择的标签(如果有的话). hide.fe.tab | 事件在标签隐藏时触发. 使用 event.targetevent.relatedTarget 分别来定位当前标签和将要显示的标签. hidden.fe.tab | 事件在标签隐藏完毕时触发. 使用 event.targetevent.relatedTarget 分别来定位当前标签和将要显示的标签.

$('a[data-toggle="tab"]').on('shown.fe.tab', function (e) {
  // e.relatedTarget
  // e.target
})

End

Thanks to Bootstrap