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

@shawyu/contextmenu

v1.1.1

Published

contextmenu

Downloads

14

Readme

@shawyu/contextmenu

contextmenu.js 是一款轻量的JavaScriptNode.js插件。不依赖任何第三方库。专门用于Web应用中的右键菜单功能。ContextMenu不需要将其自身绑定到触发对象上,这使得它非常灵活,可以随时注入和删除触发器,而不必重新初始化或更新菜单。

Github地址

https://github.com/shawyuu/js-plugin/tree/main/contextmenu

开始使用

npm安装

npm install @shawyu/contextmenu

script引入

<script src="../contextmenu/index.js"></script>

import引入

import Contextmenu from '@shawyu/contextmenu'

使用一

Contextmenu.init({
    target:"selector", /* 支持类名和id选择器,类名最好唯一,多个相同类名只获取第一个,在init方法中为必填参数 */
	menu:["关闭全部","关闭当前","关闭其他","关闭右侧"], /* 不支持对象数组 */
	success:(index)=>{
		console.log('序号',index)
	}
})

使用二

<div>
    <div onclick="handle(window.event)">菜单一</div>
    <div onclick="handle(window.event)">菜单二</div>
</div>
function handle(e){
    e.preventDefault(); //e为当前事件对象
    e.stopPropagation();
    let x = e.pageX; // 鼠标点击的位置
    let y = e.pageY;
    Contextmenu.show({
        pointX:x,
        pointY:y,
        menu:["关闭全部","关闭当前","关闭其他","关闭右侧"],
        success:(index)=>{
            console.log('序号',index)
        }
    })
}

所有属性

| 属性 | 类型 | 默认值 | 必需 | 描述 | |--------------|--------------------------|------|-------|---------------| | menu | Array.<string\|number> | [] | YES | 菜单列表 | | target | string | | NO | 选择器 | | pointX | number | | NO | 鼠标箭头相对屏幕的x坐标 | | pointY | number | | NO | 鼠标箭头相对屏幕的y坐标 | | ~~callback~~ | function | | NO | 菜单点击回调方法 | | success | function | | NO | 右键成功点击后的的回调函数 |

版本日志

1.0.0
新版本

1.1.0

废弃callback
新增target属性 selector改为 target获取
新增pointX和pointY 必需同时存在时生效

1.1.0

不再需要new Contextmenu()来创建实例,直接引用即可使用,单例。