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

@ctmobile/ui-jdcategorytab-sd

v1.0.1

Published

支持移动端的UI组件-京东分类列表

Downloads

19

Readme

JdCategoryTab

基本布局

常见的布局如下:


<div class="ct-jdcategorytab">
  <div class="ct-jdcategorytab-menu">
    <ul>

      ...
    </ul>
  </div>
  <ul class="ct-jdcategorytab-tab">

      ...
  </ul>
</div>
  • ct-jdcategorytab - 代表是一个JdCategoryTab组件
    • ct-jdcategorytab-menu - 代表菜单
      • li - 代表菜单项
    • ct-jdcategorytab-tab - 代表面板
      • li - 代表面板项

初始化


  import JdCategoryTab from @ctmobile/ui-jdcategorytab;
  const jdcategorytab = JdCategoryTab(el);

例子

html


<dl>
  <dt>
    <h3>基本</h3>
  </dt>
  <dd>

  </dd>
</dl>

<dl>
  <dt>
    <h3>动态添加</h3>
    <div class="toolbar">
      <div class="toolbar">
        <button id="ct-jdcategorytab-dynamic-addbtn">添加</button>
      </div>
    </div>
  </dt>
  <dd>

  </dd>
</dl>

<dl>
  <dt>
    <h3>滚动到指定位置</h3>
    <div class="toolbar">
      <div class="toolbar">
        <button id="ct-jdcategorytab-dynamic-scrolltopbtn">置顶</button>
        <button id="ct-jdcategorytab-dynamic-scrollbottombtn">置底</button>
      </div>
    </div>
  </dt>
  <dd>

  </dd>
</dl>

js


import $ from 'jquery';
import JdCategoryTab from '@ctmobile/ui-jdcategorytab';

function add(index) {
  return {
    menu: $(<pre><code class="html">`<li><a>菜单 ${index + 1} </a></li>`</code></pre>)[0],
    tab: $(<pre><code class="html">`<li>${index + 1}</li>`</code></pre>)[0]
  }
}

function initMenuAndTab(jdel) {
  const df1 = document.createDocumentFragment();
  const df2 = document.createDocumentFragment();
  for (let count = 0; count < 100; count++) {
    const objs = add(count);
    df1.appendChild(objs.menu);
    df2.appendChild(objs.tab);
  }
  jdel.find('.ct-jdcategorytab-menu > ul')[0].appendChild(df1);
  jdel.find('.ct-jdcategorytab-tab')[0].appendChild(df2);
}

window.onload = () => {
  // 添加
  $('#ct-jdcategorytab-dynamic-addbtn').on('click', () => {
    let length = jdcategorytabDynamicJO.find(' > .ct-jdcategorytab-menu > ul > li').length;
    const objs = add(length);
    jdcategorytabDynamicJO.find(' > .ct-jdcategorytab-menu > ul').append(objs.menu);
    jdcategorytabDynamicJO.find(' > .ct-jdcategorytab-tab').append(objs.tab);
    jdcategorytabDynamic.refresh();
    jdcategorytabDynamic.scrollTo(length);
  });

  // 置顶
  $('#ct-jdcategorytab-dynamic-scrolltopbtn').on('click', () => {
    jdcategorytabScrollto.scrollTo(0);
  });

  // 置底
  $('#ct-jdcategorytab-dynamic-scrollbottombtn').on('click', () => {
    let length = jdcategorytabScrolltoJO.find(' > .ct-jdcategorytab-menu > ul > li').length;
    jdcategorytabScrollto.scrollTo(length);
  });

  const jdcategorytabBaseJO = $('#ct-jdcategorytab-base');
  const jdcategorytabDynamicJO = $('#ct-jdcategorytab-dynamic');
  const jdcategorytabScrolltoJO = $('#ct-jdcategorytab-scrollto');

  initMenuAndTab(jdcategorytabBaseJO);
  initMenuAndTab(jdcategorytabDynamicJO);
  initMenuAndTab(jdcategorytabScrolltoJO);

  const jdcategorytabBase = JdCategoryTab(jdcategorytabBaseJO[0]);
  const jdcategorytabDynamic = JdCategoryTab(jdcategorytabDynamicJO[0]);
  const jdcategorytabScrollto = JdCategoryTab(jdcategorytabScrolltoJO[0]);
}

方法

scrollTo( index time easing) - 滚动到指定索引处

  • index-number 滚动到的索引
  • time-number 滚动所需时间
  • easing-Object动画类型(quadratic,circular,back,bounce,elastic)

refresh() - 刷新

on(type, handler) - 注册事件

  • type-string 注册事件的类型,包括[change]
  • handler-Function 注册事件的回调函数

事件

| 名称 | 说明 | | --- | --- | | change | 菜单切换 |


import $ from 'jquery';
import JdCategoryTab from '@ctmobile/ui-jdcategorytab';

window.onload = () => {
  const jdcategorytabBaseJO = $('#ct-jdcategorytab-base');
  const jdcategorytabBase = JdCategoryTab(jdcategorytabBaseJO[0]);
  jdcategorytabBase.on((index,target,tab) => {
    console.log(index,target,tab);
  });
}