简体   繁体   English

拖动 CSS 缩放元素会移除缩放(HTML5 拖动,而不是 jquery)

[英]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.为了支持更小的屏幕尺寸并避免大量计算,我尝试在调色板本身或带有它们的对象上实现 css 缩放。

I'm using HTML draggable to drag the images.我正在使用 HTML draggable 来拖动图像。 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 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.当您开始拖动蓝色框时,这是该 codepen 的快照。 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.其次,您可以使用@media 查询来设置较小设备的大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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