首页 > 解决方案 > iframe位置内的JQuery3对话框

问题描述

我正在尝试在 iframe 中打开一个对话框。当我将位置设置为:

   position: { my: 'center', at: 'center', of: window }

它指的是 iframe 的窗口。这需要我在 iframe 很长时滚动。我尝试使用:

  position: {my: "center", at: "center", of: window.top}

但我收到了这个错误:

jquery.min.js:3 Uncaught TypeError: Cannot read property 'defaultView' of undefined
    at La (jquery.min.js:3)
    at Ma (jquery.min.js:3)
    at Function.css (jquery.min.js:3)
    at Object.get (jquery.min.js:3)
    at Function.css (jquery.min.js:3)
    at jquery.min.js:4
    at S (jquery.min.js:3)
    at jQuery.fn.init.r.fn.<computed> [as outerWidth] (jquery.min.js:4)
    at d (jquery-ui.custom.min.js:formatted:614)
    at jQuery.fn.init.e.fn.position (jquery-ui.custom.min.js:formatted:666)

标签: jqueryjquery-uiiframemodal-dialogposition

解决方案


您可以考虑以下几点:

position: { my: 'center', at: 'top', of: window }

请参阅:https ://api.jqueryui.com/position/

at部分可以使用水平和垂直元素。

定义目标元素上的哪个位置对齐定位的元素:“水平垂直”对齐。有关可能值的完整详细信息,请参阅my选项。百分比偏移量是相对于目标元素的。

在查看my定义时,它说:

定义要定位的元素上的哪个位置与目标元素对齐:“水平垂直”对齐。单个值,例如"right"将被规范化为"right center""top"将被规范化为"center top"(遵循 CSS 约定)。可接受的水平值:"left", "center", "right". 可接受的垂直值:"top", "center", "bottom". 示例:"left top""center center"。每个维度还可以包含偏移量,以像素或百分比为单位,例如"right+10 top-25%"。百分比偏移量是相对于被定位的元素的。


推荐阅读