Coder Social home page Coder Social logo

tiny-context-menu's Introduction

tiny-context-menu

yet another context menu

Usage

add following styles to your css/less/sass file.

.tiny_context_menu {
  border: 1px solid #e3e4e5;
  background: #fff;
  width: 250px;
  box-shadow: 2px 2px 12px #e3e4e5;
  padding: 5px 0;
}
.tiny_context_menu .menu-item {
  padding: 5px 35px;
  font-size: 14px;
  user-select: none;
}
.tiny_context_menu .menu-item:hover {
  background: #e3e4e5;
}
import Menu from 'tiny-context-menu';

const menu = new Menu();
menu.add('button1', () => console.log('button1'));
menu.add('button2', () => console.log('button2'));
menu.add('button3', () => console.log('button3'));
menu.mount('body');
document.querySelector('.parent').addEventListener('contextmenu', (e) => {
  e.preventDefault();
  menu.updatePosition(e.pageX, e.pageY);
  menu.show();
});
document.querySelector('.parent').addEventListener('click', () => { menu.hide(); })

API

menu.add(name, click, condition)

add name, click event to the context menu.

menu.add('button', () => { console.log('button'); })

menu.updatePosition(x, y)

update positon of the context menu

menu.update(0, 0);

menu.show()

show context menu;

menu.hide()

hide context menu

tiny-context-menu's People

Contributors

gnosis23 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.