简体   繁体   English

Jquery可在父框架和子框架之间进行排序和拖拽

[英]Jquery Sortable and Draggable between parent and child frame

I am trying to implement jQuery Draggable|Droppable|Sortable between a parent and child frame. 我试图在父框架和子框架之间实现jQuery Draggable | Droppable | Sortable。 I have a this prototype but there is some weird behavior happening 我有一个这样的原型,但有一些奇怪的行为发生

win = document.getElementById('frame').contentWindow;

element = win.document.getElementById('sortable');
$(element).sortable();
console.log(element);
$( "#draggable" ).draggable({
      connectToSortable: $(element),
     iframefix: true,
    helper: function() {return $("<div/>").css('background-color','red');}
});

The iframe page also contains iframe页面还包含

$("#sortable").sortable();

Here is the jsfiddle http://jsfiddle.net/vxAzs/5/ 这是jsfiddle http://jsfiddle.net/vxAzs/5/

It works fine when I try to drop the element on the iframe but when I try to sort the elements on the iframe the element sticks to the click event of both pages I think (so it doesn't get dropped until I click on both parent and iframes). 当我尝试将元素放在iframe上时,它工作正常,但是当我尝试对iframe上的元素进行排序时,元素会粘到我认为的两个页面的click事件上(所以在我点击两个父项之前它不会被删除和iframe)。 I think it is something to do with the .sortable() call in both parent and iframe but if I remove that the droppable stops working. 我认为这与父和iframe中的.sortable()调用有关,但如果我删除了droppable停止工作。

ok, here is how I am doing this one.. To create Drag on an element from parent frame and drop it in a sortable list in the iframe, I created draggable on the element of parent frame from inside the iframe 好吧,这是我如何做这一个..要从父框架创建一个元素拖放并将其放在iframe的可排序列表中,我从iframe内部的父框架元素创建了draggable

win = document.getElementById('<identifier for Iframe>').contentWindow;
win.jQuery(dragelement,parent.document).draggable({
connectToSortable : $("#sortable")
)}

Works like a charm! 奇迹般有效!

comment this line in your code, 在你的代码中注释这一行,

//$(element).sortable({iframefix:true});

here is the fiddle : link 这里是小提琴: 链接

iframeFix is case sensitive: Change iframeFix区分大小写:更改

iframefix: true,

to

iframeFix: true,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM