【问题标题】:Invalid mouse offset for cross-frame draggable + sortable跨框架可拖动 + 可排序的无效鼠标偏移
【发布时间】:2013-05-24 09:01:16
【问题描述】:

我们目前正在尝试实现 jQuery UI 提供的可拖动对象和可排序对象之间的跨帧拖动。这现在工作正常。但是,当从父框架拖动到子框架时,鼠标偏移似乎关闭了——请看这个小提琴:http://jsfiddle.net/r5nfe/6/

父代码:

$('#my-frame').load(function () {
    $('.draggable').draggable({
        appendTo: 'body',
        helper: 'clone',
        iframeFix: true,
        revert: 'invalid',
        connectToSortable: $('#my-frame').contents().find('.sortable'),
        cursorAt: { top: 0, left: 0 } 
    });

    $('#my-frame').contents().find('.sortable').sortable({
        iframeFix: true,
        cursorAt: { top: 0, left: 0 } 
    });
});

子框架中的代码:

var containers = $('.sortable');
containers.sortable({
    connectWith: containers,
    cursor: 'move',
    revert: true,
    cursorAt: { top: 0, left: 0 } 
});

谁能告诉我们如何修复鼠标偏移?

【问题讨论】:

标签: javascript iframe jquery-ui-sortable jquery-ui-droppable


【解决方案1】:

解决方案 2 更新

我添加这个js函数是因为当你在iframe中添加太多可拖动元素时,如果向下滚动,拖动元素可能会被可排序元素重叠

$('.draggable').on('dragstop',autoResize);


function autoResize(){
    var newheight;
    if(document.getElementById){
        newheight=document.getElementById('my-frame').contentWindow.document .body.scrollHeight;
    }
    newheight=newheight+100;
    $('#my-frame').css('height',newheight);
}

这里是new jsfiddle
结束解决方案 2 更新

这个问题似乎是一个错误,有人提出了他的解决方案(基本上是一种解决方法):trasparent div solution

1 我的第一个解决方案,不改代码,可能是把iframe放在可拖动的东西之前,如图here,代码:

<iframe id="my-frame" src="/VqxGf/3/show"></iframe>
<ul>
    <li class="draggable">Drag me</li>
    <li class="draggable">Drag me 2</li>
    <li class="draggable">Drag me 3</li>
</ul>

2 另一个似乎可行的解决方案是使用 style 属性:包含可拖动

的 ul 的绝对位置
  • s,对于框架中可排序的内容,有一点margin-top,也许,frameborder=0。 jsfiddle 主页面:
    <ul style="position:absolute">
        <li class="draggable">Drag me</li>
        <li class="draggable">Drag me 2</li>
        <li class="draggable">Drag me 3</li>
    </ul>
    <iframe frameborder="0" id="my-frame" src="/ATu6F/30/show"></iframe>
    

    iframe 页面:

    <ul id="sortable" style="margin-top:100px" class="sortable idle">
        <li>Sortable</li>
        <li>Sortable 2</li>
        <li>Sortable 3</li>
    </ul>
    
    <ul id="sortable2" class="sortable idle">
        <li>Sortable</li>
        <li>Sortable 2</li>
        <li>Sortable 3</li>
    </ul>
    

    希望这会有所帮助。

    请查看本文开头的编辑

  • 【讨论】:

    • 谢谢@JoDev 我想让你知道我更新了该解决方案以避免滚动时可拖动的内容与可排序的内容重叠
    • 当我运行这段代码时,我得到这个错误:TypeError: undefined is not an object (evalating 'this.overflowOffset.top')
    • 是的,这段代码给出了我在使用 jquery-ui-1.11.2 时提到的错误
    • 这是一个错误。见bugs.jqueryui.com/ticket/15047 这个项目解决了droppables 的问题:github.com/maxazan/jquery-ui-droppable-iframe。但它不适用于可排序(github.com/maxazan/jquery-ui-droppable-iframe/issues/2),并且作者似乎没有维护这个项目。我认为解决方案可能是类似的,需要在sortable.refreshPositions(); 内修复 jQueryUi 中的某些内容
    【解决方案2】:

    我已经尝试过this。但它并不完美。

    我将appendTo 更改为parent.body,将cursorAt 更改为顶部参数100

    $('#my-frame').load(function () {
    $('.draggable').draggable({
        appendTo: 'parent.body',
        helper: 'clone',
        iframeFix: true,
        revert: 'invalid',
        connectToSortable: $('#my-frame').contents().find('.sortable'),
        cursorAt: { top: 100, left: 0 } 
    });
    
    $('#my-frame').contents().find('.sortable').sortable({
        iframeFix: true,
        cursorAt: { top: 0, left: 0 } 
    });
    });
    

    【讨论】:

      猜你喜欢
      • 2010-11-17
      • 1970-01-01
      • 2011-02-16
      • 1970-01-01
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多