react-draggable icon indicating copy to clipboard operation
react-draggable copied to clipboard

Percentage based drag system

Open AndrewRayCode opened this issue 10 years ago • 4 comments

I'm trying to create resizable split panes. If a draggable component (the handle between panes) is set to a % offset from its parent, it's much more convenient. I'm not sure I can fanangle it with a transform: translate setup

AndrewRayCode avatar Jun 13 '15 20:06 AndrewRayCode

I have a similar use case and I'm using DraggableCore to handle it. Just manually set the left and top styles as a percentage on DraggableCore's child.

joeporpeglia avatar Oct 03 '16 21:10 joeporpeglia

@joeporpeglia Could you give an example on how you did that?

phillfer avatar Apr 28 '17 20:04 phillfer

For anyone still looking for an answer, this might be helpful: I am storing x, y positions of the item relative to its parent/bounds container. Then just setting position absolute on the Child and passing top and left styles after converting the float to %.

<Draggable
  key={i}
  axis="both"
  handle=".handle"
  position={null}
  cancel=".content-is-editable"
  // grid={[25, 25]}
  scale={1}
  disabled={props.disabled}
  {...dragHandlers}
>
  <div
    className="handle cursor-move absolute"
    id={item.id}
    datatype={item.item_type}
    style={{ left: `${item.x * 100}%`, top: `${item.y * 100}%` }}
  >
    <div className="item item--media text-serif text-styled-500">
      {item.content}
    </div>
  </div>
</Draggable>;

designcrumble avatar Feb 22 '20 09:02 designcrumble

For anyone still looking for an answer, this might be helpful: I am storing x, y positions of the item relative to its parent/bounds container. Then just setting position absolute on the Child and passing top and left styles after converting the float to %.

<Draggable
  key={i}
  axis="both"
  handle=".handle"
  position={null}
  cancel=".content-is-editable"
  // grid={[25, 25]}
  scale={1}
  disabled={props.disabled}
  {...dragHandlers}
>
  <div
    className="handle cursor-move absolute"
    id={item.id}
    datatype={item.item_type}
    style={{ left: `${item.x * 100}%`, top: `${item.y * 100}%` }}
  >
    <div className="item item--media text-serif text-styled-500">
      {item.content}
    </div>
  </div>
</Draggable>;

Did you find a way? I tried implementing a condition to implement the dragging percentage based on the parent element's width compared to the current element width, but It did not work on iPhone.

isaac-wahba avatar Jan 03 '23 04:01 isaac-wahba