我想做的是
我是这里,但问题与我最初想的不一样。
我使用的CMS已经为可排序组设置了选项,我不想更改它们。我想要做的是将具有<div>的class of "not-sortable"排除在可排序之外。
包含在CMS中的当前设置
$('.meta-box-sortables').sortable({
placeholder: 'sortable-placeholder',
connectWith: '.meta-box-sortables',
items: '.postbox',
handle: '.hndle',
cursor: 'move',
delay: ( isMobile ? 200 : 0 ),
distance: 2,
tolerance: 'pointer',
forcePlaceholderSize: true,
helper: 'clone',
opacity: 0.65,
});如前所述,我已经设置了一个'postbox'部分,并添加了一个'not-sortable'类。然后,在一个定制的.js文件中,我有以下内容。
我的自定义设置
jQuery(function($) {
$(".meta-box-sortables").sortable({
items : ':not(.not-sortable)'
});
});这样就消除了移动任何以前可拖动的部分的能力。因此,我似乎要重写items:选项。
有没有一种方法,我可以做到这一点,而不覆盖原来的设置,或我错在我的思路在这里?
发布于 2015-06-07 16:49:52
可以使用接受对象的选项方法的形式:
jQuery(function($) {
$(".meta-box-sortables").sortable("option", {
items: ":not(.not-sortable)"
});
});这样,您没有指定的设置将被保留。
对于前面存储在item选项中的选择器的详细说明,不幸的是,您必须再次指定它:
items: ".postbox:not(.not-sortable)"与以前的值相对应是可行的:
items: $(".meta-box-sortables").sortable("option", "items")
+ ":not(.not-sortable)"但是,如果items包含一个更复杂的选择器(例如多选择器),它将失败:
items: ".postbox, .other", // Whoops.https://stackoverflow.com/questions/30696012
复制相似问题