Coder Social home page Coder Social logo

x-ryl669 / displace Goto Github PK

View Code? Open in Web Editor NEW

This project forked from catc/displace

0.0 3.0 0.0 776 KB

Minimal javascript library for creating movable DOM elements

Home Page: https://catc.github.io/displace

License: MIT License

JavaScript 100.00%

displace's Introduction

displace.js

A minimal javascript library to enable moveable DOM elements.

  • ~1.2kb gzipped
  • supports mobile touch
  • no dependencies/bloat
  • IE9+

Getting started

Reference

Install via npm:

npm install --save displacejs

Reference displace.min.js and use via displace:

// es6
import displace from 'displacejs';

// commonjs
let displace = require('displace');

// if using globally in browser
const displace = window.displacejs;

Initialize

Initialize and use:

// initial
const d = displace(document.querySelector('.some-div'), options);

API

Methods

displace(element, options)

Creates a new displace instance with a DOM element. For options, see below.

reinit()

Runs setup again. Useful when divs have been moved or resized.

displace.destroy()

Removes event listeners and destroys instance.


Options

constrain

Constrains element to its parent container

Default: false

relativeTo

Constrains element to the specified DOM element. Requires constrain to be true.

Default: null

handle

Assigns a child element as the moveable handle for the parent element.

Default: null

highlightInputs

Allows you to highlight text in inputs and textareas by disabling drag events originating from those elements.

Default: false

onMouseDown

Function that is triggered when user clicks down on moveable element.

Default: null

onMouseMove

Function that is triggered when user moves element.

Default: null

onMouseUp

Function that is triggered when user clicks up on moveable element.

Default: null

onTouchStart

Function that is triggered when initiates touch event.

Default: null

onTouchMove

Function that is triggered when moves element during touch event.

Default: null

onTouchStop

Function that is triggered when user ends touch event.

Default: null

Development

Clone the repo and npm install. Available npm scripts are:

  • build library: lib-build
  • library development (watch src files and build on change): lib-dev
  • docs development (port 3001): docs-dev

displace's People

Contributors

catc avatar x-ryl669 avatar

Watchers

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