如何避免将宽度和高度添加到拖动项目中?
当我使用可拖动且可排序时,jQuery总是设置内联风格的宽度和高度,这确实很烦人。
这是我将项目从.structure
转移到.sortable
的脚本:
$( function()
{
$( ".sortable" ).sortable();
$( ".item" ).draggable({
connectToSortable: ".sortable",
helper: "clone"
});
});
这是我的HTML代码
<div class="structure">
<div class="item">New block</div>
<div class="item">New headline</div>
</div>
<div class="sortable"></div>
.Item
是块元素,当我将它们移至。可容纳
它们获得宽度和高度,而不是以宽度:100%
传播。这就是.Item
拖动后的样子:
<div class="item ui-draggable ui-draggable-handle" style="width: 69.75px; height: 18px;">New block</div>
在这里您可以看到 https://codepen.io/alphafrau/alphafrau/pen/nwyxmgw
这些设置以及如何避免这种情况。你有什么想法吗?
亲切的问候 彼得
When I use draggable and sortable, jQuery always sets inline-styles for width and height which is really annoying.
This is my script to move items from .structure
to .sortable
:
$( function()
{
$( ".sortable" ).sortable();
$( ".item" ).draggable({
connectToSortable: ".sortable",
helper: "clone"
});
});
and this is my HTML code
<div class="structure">
<div class="item">New block</div>
<div class="item">New headline</div>
</div>
<div class="sortable"></div>
The .item
are block elements, when I move them to .sortable
they get a width and height instead of spreading at a width: 100%
. This is what a .item
looks like after dragging:
<div class="item ui-draggable ui-draggable-handle" style="width: 69.75px; height: 18px;">New block</div>
Here you can see that
https://codepen.io/alphafrau/pen/NWyXmgw
I have no idea why jQuery adds these settings and how to avoid that. Do you have any ideas?
Kind regards
Peter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$(this)
元素“可排序事件”所指的是指橙色div,其中所有孩子divs中的所有孩子都必须样式。下面的代码中有
console.log
的事件,以便您意识到发生了什么。The
$(this)
element the sortable events act on refers to the orange div with all the child divs in it, you have to style them.There are
console.log
's and events in the code below for you to realize what's going on.使用
宽度:100%!重要
它可能会为您提供帮助。Use
width:100% !important
It may help you.