Coder Social home page Coder Social logo

Comments (3)

taye avatar taye commented on May 15, 2024

Yeah, I've been meaning to add an option for this. For now, here's an example of how to do it manually: http://plnkr.co/edit/cFVVS63pVIw3zyP5VEzS

.on('dragstart', function (event) {
  var
    containerRect = interact.getElementRect(event.target.parentNode),
    elementRect = interact.getElementRect(event.target);

  var restrictRect = {
    left: containerRect.left + (event.pageX - elementRect.left),
    top : containerRect.top  + (event.pageY - elementRect.top ),

    right : containerRect.right  - (elementRect.right  - event.pageX),
    bottom: containerRect.bottom - (elementRect.bottom - event.pageY)
  };

  interact('.compare-left-item').restrict({
    drag: restrictRect
  });

In this case, the intended restriction, containerRect, is the rect of the parent element. When a drag starts, the restriction is recalculated to account for the position of the mouse and the rect of the target element.

from interact.js.

dexusnl avatar dexusnl commented on May 15, 2024

Thanks!
And for your quick reply to.

I put the code in the onstart event from interact.draggable itself instead of separately.
Works like a charm.

from interact.js.

taye avatar taye commented on May 15, 2024

Excellent! I'll leave this issue open until a solution is built into interact.js.

from interact.js.

Related Issues (20)

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.