24

Moveable is Draggable! Resizable! Scalable! Rotatable!

 4 years ago
source link: https://www.tuicool.com/articles/NNVrqqE
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

EVVfmij.png!web

Moveable

Moveable is Draggable, Resizable, Scalable, Rotatable

Demo / React Moveable / Preact Moveable

Moveable Draggable Resizable Scalable Rotatable FveUZb6.gifziyqUfn.gifBfeAr2V.gifi2YJNja.gif

⚙️ Installation

npm

$ npm i moveable

scripts

<script src="//daybrush.com/moveable/release/latest/dist/moveable.min.js"></script>

:page_facing_up: Documents

:rocket: How to use

import Moveable, {
    OnDragStart
    OnDrag,
    OnDragEnd,
    OnResizableStart
    OnResizable,
    OnResizableEnd,
    OnScaleStart
    OnScale,
    OnScaleEnd,
    OnRotateStart
    OnRotate,
    OnRotateEnd,
} from "moveable";

const moveable = new Moveable(document.body, {
    target: document.querySelector(".target"),
    container: null,
    draggable: true,
    resizable: true,
    scalable: true,
    rotatable: true,
    origin: true,
}).on("dragStart", ({ target }: OnDragStart) => {
    console.log("onDragStart", target);
}).on("drag", ({
    target,
    beforeDelta, beforeDist,
    left, top,
    right, bottom,
    delta, dist,
    transform,
}: OnDrag) => {
    console.log("onDrag left, top", left, top);
    // target!.style.left = `${left}px`;
    // target!.style.top = `${top}px`;
    console.log("onDrag translate", dist);
    target!.style.transform = transform;
}).on("dragEnd", ({ target, isDrag }: OnDragEnd) => {
    console.log("onDragEnd", target, isDrag);
}).on("resizeStart", ({ target }: OnResizeStart) => {
    console.log("onResizeStart", target);
}).on("resize", ({ target, width, height, dist, delta }: OnResize) => {
    console.log("onResize", target);
    delta[0] && (target!.style.width = `${width}px`);
    delta[1] && (target!.style.height = `${height}px`);
}).on("resizeEnd", ({ target, isDrag }: OnResizeEnd) => {
    console.log("onResizeEnd", target, isDrag);
}).on("scaleStart", ({ target }: OnScalableStart) => {
    console.log("onScaleStart", target);
}).on("scale", ({
    target, scale, dist, delta, transform,
}: OnScale) => {
    console.log("onScale scale", scale);
    target!.style.transform = transform;
}).on("scaleEnd", ({ target, isDrag }: OnScaleEnd) => {
    console.log("onScaleEnd", target, isDrag);
}).on("rotateStart", ({ target }: OnRotateStart) => {
    console.log("onRotateStart", target);
}).on("rotate", ({ target, delta, dist, transform }: onRotate) => {
    console.log("onRotate", dist);
    target!.style.transform = transform;
}).on("rotateEnd", ({ target, isDrag }: OnRotateEnd) => {
    console.log("onRotateEnd", target, isDrag);
});

:package: Packages

  • react-moveable : A React Component that create Moveable, Draggable, Resizable, Scalable, Rotatable.
  • preact-moveable : A Preact Component that create Moveable, Draggable, Resizable, Scalable, Rotatable.

:star:️ Show Your Support

Please give a :star:️ if this project helped you!

:clap: Contributing

If you have any questions or requests or want to contribute to moveable or other packages, please write the issue or give me a Pull Request freely.

:beetle: Bug Report

If you find a bug, please report to us opening a new Issue on GitHub.

:memo: License

This project is MIT licensed.

MIT License

Copyright (c) 2019 Daybrush

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK