gpt4 book ai didi

jQuery UI Sortable 将拖动对象的类添加到占位符以确定大小

转载 作者:行者123 更新时间:2023-12-01 01:04:18 26 4
gpt4 key购买 nike

我使用 sortable 来对不同宽度 x 高度的 div 进行排序,并使用 masonry 来清理空白空间。如何将要排序的 div 的类传递给占位符,以便它们具有相同的大小?

盒子有单单、双单等类别......以确定尺寸。

示例:http://jsfiddle.net/c3mdigital/fTBbc/17/

问题是类没有被通过。当 Sortable 无法识别占位符选项但将可见性设置为隐藏时,它会添加该类。

代码:

//The extra ajax stuff is to save the sort order to WordPress menu order.
$(document).ready(function() {
$('#edit').click(function() {

var itemList = $('.sortable');

itemList.sortable({

start: function(event, ui) {

var plus = ui.item.hasClass('double-single') ? 'double-single' : 'single-single';
var placeholder =
itemList.sortable("option", "placeholder", 'placeholder ' + plus );

},
update: function(event, ui) {
$('#loading-animation').show(); // Show the animate loading gif while waiting
opts = {
url: MyAjax.ajaxurl,
// ajaxurl is defined by WordPress and points to /wp-admin/admin-ajax.php
type: 'POST',
async: true,
cache: false,
dataType: 'json',
data: {
action: 'item_sort',
// Tell WordPress how to handle this ajax request
order: itemList.sortable('toArray').toString() // Passes ID's of list items in 1,3,2 format
},
success: function(response) {
$('#loading-animation').hide(); // Hide the loading animation
return;
},
error: function(xhr, textStatus, e) { // This can be expanded to provide more information
alert(e);
// alert('There was an error saving the updates');
$('#loading-animation').hide(); // Hide the loading animation
return;
}
};
$.ajax(opts);
}
});


});

$('.sortable').disableSelection();
});

$(function() {
$('#sort').click(function() {
$('#sortable1').masonry({
columnWidth: 325,
itemSelector: '.ui-state-default'
});
});
});

最佳答案

您不能在创建事件上执行此操作,该事件会在您初始化可排序时触发。相反,您可以设置 placeholder:'placeholder',并使用 start 事件向 ui.placeholder 添加额外的类,使其成为正确的尺寸:

    itemList.sortable({
placeholder: 'placeholder',
start: function(event, ui) {
var plus;
if(ui.item.hasClass('single-single')) plus = 'single-single'; else
if(ui.item.hasClass('single-double')) plus = 'single-double'; else
if(ui.item.hasClass('single-triple')) plus = 'single-triple'; else
if(ui.item.hasClass('double-single')) plus = 'double-single'; else
if(ui.item.hasClass('double-double')) plus = 'double-double'; else
if(ui.item.hasClass('double-triple')) plus = 'double-triple'; else
plus = 'single-single';
ui.placeholder.addClass(plus);
}});

您可能想要实现更复杂的类检测方法,它只是一个快速复制粘贴,以便我可以测试它。

这是演示:http://jsfiddle.net/fTBbc/24/

关于jQuery UI Sortable 将拖动对象的类添加到占位符以确定大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6063277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com