如何更新jQuery Mobile全局弹出窗口的位置
How do I update the position of a jQuery Mobile global popup?
我有一个jQuery Mobile全局弹出窗口,其内容是动态生成的。所以默认情况下它是空的。
我正在收听beforeposition
事件以捕获正在打开的弹出窗口。然后我加载一个配置文件/内容文件,生成内容并将其附加到弹出窗口中。
然而,当我添加时,JQM已经计算好了弹出窗口的位置,所以它会放在屏幕上。
以下是我正在做的:
$(document).find("#global-popup")
.on("popupbeforeposition", function (e) {
factory.util.generatePopupContents(app.generateActionObject(e));
});
factory.util.generatePopupContents = function (obj) {
var i, j, promises, fragment, popup, reference, state;
popup = obj.gadget,
reference = popup.getAttribute("data-reference"),
state = popup.getAttribute("data-state");
// don't reload if same popup is opened
if (state !== reference) {
if (reference === null) {
util.errorHandler({
"error": "Global Bindings: No handler for popup"
});
} else {
popup.setAttribute("data-state", reference);
popup.setAttribute("data-reference", reference);
promises = [];
// fetch content > THIS WILL LOAD A JSON DICT
app.fetchConfiguration({
"storage": app.default_dict.storage_dict.settings,
"file": app.default_dict.storage_dict.gadgets,
"attachment": reference,
"pass": undefined
})
.then(function (reply) {
obj.gadget.setAttribute("data-reference", reference);
// loop children in JSON dict
if (reply.children) {
for (i = 0; i < reply.children.length; i += 1) {
promises[i] = app.setContent(reply.children[i], {}, false);
}
}
return RSVP.all(promises)
})
.then(function (content) {
// create a fragment and append generated content
fragment = document.createDocumentFragment();
for (j = 0; j < content.length; j += 1) {
fragment.appendChild(content[j]);
}
// translate fragment if needed
if (i18n) {
map.actions.translateNodeList(fragment);
}
// empty gadget and reload
obj.gadget.innerHTML = "";
obj.gadget.appendChild(fragment);
})
.fail(util.errorHandler);
}
}
};
我想知道在添加内容后如何重新定位弹出窗口($(obj.gadget)
)。
我试过了:
$(obj.gadget).trigger("updatelayout");
或者:
$(obj.gadget).popup("reposition", {"y": 0});
但它们都不起作用。在document
上触发updatelayout也不起作用。
问题
如何更新全局弹出窗口的位置?
您需要将其绑定到popupafteropen
。
$(".selector").on("popupafteropen", function () {
$(this).popup("reposition", {
"positionTo": "window",
// or
x: 100,
y: 200
});
});
演示
相关文章:
- AngularJS中的封装窗口全局变量
- 全局窗口热键在最小化chrome窗口时调用js函数
- 用自定义javascript全局命名空间替换窗口
- Jasmine在全局窗口对象上创建本地JS函数的Spy
- 如何更新jQuery Mobile全局弹出窗口的位置
- 像cookie这样的全局变量,它在回发后保留值,但应该为不同的实例保存不同的值(选项卡/窗口)
- 确定是否在不使用任何全局变量的情况下加载了窗口
- Javascript:全局变量转到“窗口”或“全局”,但全局函数不会.全球 FN 去哪儿了
- 全局变量只是“窗口”对象的属性吗?
- 我应该使用 self 还是窗口来引用全局范围
- jqm 中的全局弹出窗口
- 为剑道UI窗口添加全局功能
- 为什么全局作用域中的变量被分配给窗口对象
- 为什么javascript将函数中的(局部)变量视为全局(窗口)变量
- 为什么这会返回对全局窗口对象的引用,即使“this”在另一个函数中
- webpack块中未定义的全局窗口变量
- JS查询-全局窗口对象
- 全局“窗口”是如何实现的?引用影响生命周期中的垃圾收集
- 当我们将一个方法存储在一个变量中,然后调用它时,为什么上下文对象会变为全局窗口对象
- JavaScript使对象一个全局窗口对象?(无冲突功能)