在iframe中使用jQuery可排序

我正在尝试在iframe中加载一些html并使该html页面中的某些元素可排序:

的jsfiddle

JS:

var _iframe = $('iframe'); var containment = _iframe.contents().find( "modules" ); if(containment.data('sortable')) containment.sortable('destroy'); containment.sortable({ stop: function (event, ui) { console.log('STOP: I am never called'); }, start: function (event, ui) { console.log('START: I am called with a delay!'); }, containment: containment, placeholder: "sortable-placeholder", items: "> module", delay: 10, forcePlaceholderSize: true, helper: 'clone', zIndex: 10000 }); 

这会导致一些意外的行为,例如延迟启动事件根本没有停止事件

仅当内容位于iframe内时才会出现此问题。 这是一个没有iframe 的版本 (以及它应该如何工作)

尝试对此版本中的元素进行排序(并让控制台保持打开状态)

似乎唯一可行的解​​决方案是将代码放在iframe中。 当父母打扫他的房间时,也许iframe不喜欢它…