Comments (3)
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.
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.
Excellent! I'll leave this issue open until a solution is built into interact.js.
from interact.js.
Related Issues (20)
- Missing TypeScript types (e.g. `styleCursor` option) HOT 1
- Issue on dropzones with 1.10.20 release HOT 7
- How to implement elements snapping to each other functionality? HOT 1
- @Interacrt/Interact cannot trigger the move event
- draggable and gesturable div, behavior lock with inertia
- Issue with Module Parsing in Project Using react-multi-crops HOT 3
- Vite production builds fail after v1.10.25
- TypeScript compile errors - version 1.10.26 HOT 4
- Resize modifier - wrong types HOT 1
- Gestures not working in ShadowDom
- Incompatible with Angular (v17) HOT 3
- New Snap syntax not working HOT 1
- Can't drag element when wrap drag item inside div HOT 1
- Restricting a drag with parent as origin. HOT 4
- Set snap on or off by user
- Demo Page down (https://interactjs.io/) HOT 1
- Is there a way to set the z-index of dropactive?
- interactjs.io is down
- mouseButtons typescript type definitions
- Web server is down (interactjs.io) HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from interact.js.