首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jQuery UI下拉区域在滚动的iframe中的错误偏移量

jQuery UI下拉区域在滚动的iframe中的错误偏移量
EN

Stack Overflow用户
提问于 2015-04-22 21:20:27
回答 1查看 949关注 0票数 7

我对jQuery可拖式和可下拉式有个问题。我需要拖动一个拖在一个可下拉式,这是放置在一个iframe内。这工作正常,直到我滚动的iframe。不更新可下垂的坐标。

这个问题在这个fiddle中演示了。

我正在使用下面的解决办法,使拖拽和下降到iframes在最初的位置。它计算正确的偏移量,但不使用iframe的滚动偏移量。我试过了,但没能让它调整,这样它就会考虑到滚动偏移。

代码语言:javascript
复制
// Create new object to cache iframe offsets
$.ui.ddmanager.frameOffsets = {};

// Override the native `prepareOffsets` method. This is almost
// identical to the un-edited method, except for the last part!
$.ui.ddmanager.prepareOffsets = function (t, event) {
    var i, j,
        m = $.ui.ddmanager.droppables[t.options.scope] || [],
        type = event ? event.type : null, // workaround for #2317
        list = (t.currentItem || t.element).find(":data(ui-droppable)").addBack(),
        doc, frameOffset;

    droppablesLoop: for (i = 0; i < m.length; i++) {

        //No disabled and non-accepted
        if (m[i].options.disabled || (t && !m[i].accept.call(m[i].element[0], (t.currentItem || t.element)))) {
            continue;
        }

        // Filter out elements in the current dragoged item
        for (j = 0; j < list.length; j++) {
            if (list[j] === m[i].element[0]) {
                m[i].proportions().height = 0;
                continue droppablesLoop;
            }
        }

        m[i].visible = m[i].element.css("display") !== "none";
        if (!m[i].visible) {
            continue;
        }

        //Activate the droppable if used directly from draggables
        if (type === "mousedown") {
            m[i]._activate.call(m[i], event);
        }

        // Re-calculate offset
        m[i].offset = m[i].element.offset();

        // Re-calculate proportions (jQuery UI ~1.10 introduced a `proportions` cache method, so support both here!)
        proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight };
        typeof m[i].proportions === 'function' ? m[i].proportions(proportions) : (m[i].proportions = proportions);

        /* ============ Here comes the fun bit! =============== */

        // If the element is within an another document...
        if ((doc = m[i].document[0]) !== document) {
            // Determine in the frame offset using cached offset (if already calculated)
            frameOffset = $.ui.ddmanager.frameOffsets[doc];
            if (!frameOffset) {
                // Calculate and cache the offset in our new `$.ui.ddmanager.frameOffsets` object
                frameOffset = $.ui.ddmanager.frameOffsets[doc] = $(
                    // Different browsers store it on different properties (IE...)
                    (doc.defaultView || doc.parentWindow).frameElement
                ).offset();
            }

            // Add the frame offset to the calculated offset
            m[i].offset.left += frameOffset.left;
            m[i].offset.top += frameOffset.top;
        }
    }
}

有没有人建议解决这个问题。建议实现同样的事情,另一种方式也是非常受欢迎的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-28 10:17:58

您可以根据proportions's中的滚动量更改iframe.高度,可以使用$("iframe").contents().scrollTop()实现数量,因为您已经使用它来更改滚动数量:

代码语言:javascript
复制
proportions = {
      width: m[i].element[0].offsetWidth,
      height: m[i].element[0].offsetHeight - $("iframe").contents().scrollTop()
};

这是DEMO

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29809075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档