Code Monkey home page Code Monkey logo

selection-area's Introduction

Selection Area

npm version documentation


Simple JavaScript mouse & touch seletion area to any DOM container element.


How to use | API Reference | Demo


How to use

Download

Install with npm

npm install selection-area

Install with yarn

yarn add selection-area

From Source Code

Clone or download zipped source code into node_modules project folder.

git clone https://github.com/lucasmenendez/selection-area.git <project>/node_modules/selection-area

Import

Local dist version

Import using script html tags with vendor path:

<script src="/node_modules/selection-area/dist/selection-area.js"></script>

Or import using ES6 import:

import { SelectionArea } from 'selection-area';

CDN version

Importing with unpkg.com:

<script src="https://unpkg.com/selection-area"></script>

Example

Define container for selection area and selectable childs.

<div class="parent">
    <div class="child">0</div>
    <div class="child">1</div>
    <div class="child">2</div>
    <div class="child">3</div>
    <div class="child">4</div>
    <div class="child">5</div>
    <div class="child">6</div>
    <div class="child">7</div>
    <div class="child">8</div>
    <div class="child">9</div>
</div>

Define SelectionArea behaviour with configuration object, check available parameters here.

let config = {
    container: document.querySelector('.parent'),
    area: {
        class: 'custom-area'
    },
    targets: '.child',
    touchable: true,
    autostart: true,
    callback: selection => {
        if (selection.length == 0) alert("empty selection");
        else alert(`${ selection.length } items selected`);
    }
}

let selectable = new SelectionArea(config);

Also you can stylize the selection area element adding style yo defined class.

.custom-area {
    background: rgba(52, 152, 219, 0.2);
    border: 2px dotted #2980b9;
}

selection-area's People

Contributors

lucasmenendez 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.