I have a div that has been scaled using transform, and within it another div that is draggable. When the scale of the transformed div is not 1, the draggable div essentially disassociates from the mouse. JSFiddle here
I don’t have any control over the javascript (it is a third party component being embedded in the page). Is there a CSS solution to this, or maybe a "global" jquery solution to set the container to the body?
Relevant CSS my side:
-webkit-transform: scale(1.5);
JQuery called in 3rd party component
$('.draggable').draggable();
2
Answers
Going over the jQuery UI – Draggable documentation (https://api.jqueryui.com/draggable/).
Seems like your only chance without going custom is to alter the data with the
drag event
(more information on https://api.jqueryui.com/draggable/#event-drag ).The documentation quotes the following:
The example shows is as follows:
jQuery Draggable Example – Drag Event
Initialize the draggable with the drag callback specified:
Bind an event listener to the drag event:
Constrain movement via ui.position:
And possibly altering the example to take the position and reduce it by 1.5.
This is a workaround/alternative to your code and may not be what you are looking for…
At first I thought your issue was due to the fact that scaling does not automatically scale the orginal space an element occupies and caused some mousepos offset discrepancy. Usually this can be corrected by calculating a positive or negative
margin
relative to the scale applied. Positive for a scaled up, negative for a scaled down element and assign that to the scaled elementsmargin
.However, testing this with your Fiddle it did not have the expected result, so I opted to work around the issue:
transform: scale(..)
orscale: ..
, introduce a CSS custom property with a scale factor (--scale-factor: 1.5
)calc(..)
ulate all relevant sizes relative to the current value of--scale-factor
snippet, Fiddle, Codepen.