GithubHelp home page GithubHelp logo

dragjs's Introduction

drag js

原生实现 js 拖拽

使用

import dragJs, { getElementFronPoint } from 'pure-js-drag';

dragJs(
  fireEle, // 触发拖动的原素,这个原素的mousedown事件会触发拖动
  draggedEle, // 被拖动的原素,这个原素会被改变位置,需要css的left,top改变可以改变位置,
              // 需要预先设置这个原素的position为absolute。如果元素利用了relative。那么需要使用
              // customCbForMousemove来自己决定x,y的位置
  {
    disabledX: Boolean, // true表示无法在x轴拖动,默认false
    disabledY: Boolean, // true表示无法在y轴拖动,默认为false
    minX: number, // x轴最小的距离
    maxX: number, // x轴最大的距离
    minY: number, // y最小的距离
    maxY: number, // y最大的距离
    droppedEle: Node, // 可以放置的原素。需要在draggedEle下面的最顶层
    once: Boolean, // 是否只拖动一次
    customCbForMousemove: Function, // 自定义的mousemove回调
  },
);

// 根据clientX,clientY来获取元素的位置
getElementFromPoint(e.clientX, e.clientY);

dragjs's People

Contributors

ai01 avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

rga69061

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.