拖动CSS缩放元素删除缩放(HTML5拖动,而不是jQuery)
我正在创建一个调色板,可以在其中拖动对象。为了支持较小的屏幕尺寸并避免进行大量计算,我正在尝试在调色板本身或对象上实现CSS缩放。
我正在使用HTML拖动来拖动图像。但是,当我在缩放图像上拖动时,缩放量会消失,并且再次显示为全尺寸。这使得很难理解事情将如何下降。
这是一支代码笔,蓝色框缩小到一半。
https://codepen.io/dapepen.io/daprezjer/pen/pen/pen/pen/xxyzdom
<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);
}
当您开始拖动蓝色框时,这是该代码蛋白的快照。您会看到拖动预览的尺寸两倍,返回原来的
有什么方法可以将拖动的图像保持与缩放原件相同的大小?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
变换:比例(.5);
拖动时行不起作用。因此,最好使用响应单元直接设置宽度和高度。
其次,您可以利用@Media查询来设置较小设备的大小。
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.