简体   繁体   中英

Dragging a CSS scaled element removes scaling (HTML5 dragging, not jquery)

I'm creating a palette where objects can be dragged and dropped. To support smaller screen sizes and avoid a ton of calculations, I'm trying to implement css scaling on the palette itself, or on the objects with them.

I'm using HTML draggable to drag the images. However, when I drag on a scaled image, the scaling goes away, and it shows as the full size again. This makes it very difficult to understand how things will drop.

Here's a code pen, where the blue box is scaled down to half size.

https://codepen.io/daprezjer/pen/xxYzdOM

And the code for it:

<div id="container">
    <div id="dragging" draggable="true"></div>
</div>
#container {
  width: 500px;
  height: 500px;
  border: 1px solid black;
}
#dragging {
  width: 100px;
  height: 100px;
  background-color: blue;
  transform: scale(.5);
}

And here's a snapshot of that codepen when you start dragging the blue box. You'll see the dragging preview doubles in size, back to it's original

在此处输入图像描述

Is there any way to keep the dragged image the same size as the scaled original?

transform: scale(.5);

This line doesnt work while dragging. So better set the width and height directly using a responsive units. Secondly, you can make use of @media queries to set the size of smaller devices.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM