Jquery 移动弹出窗口在页面调整大小或滚动时在错误的位置重新打开

编程入门 行业动态 更新时间:2024-10-26 00:23:51
本文介绍了Jquery 移动弹出窗口在页面调整大小或滚动时在错误的位置重新打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在 PC 浏览器中,有一个问题,即弹出窗口在调整窗口大小时会改变其位置.我用谷歌搜索,发现 JMF 有一个错误,将 positionTo 从 origin/#codeSource 更改为 window.

在移动浏览器中,我在页面滚动时遇到了同样的问题.弹出窗口在错误的位置再次呈现.

我需要以某种方式设置正确的位置,或者避免在调整窗口大小和滚动页面时多次重新打开.

有人能给我一些建议吗?

解决方案

您需要监听 popupbeforeposition 事件并更改该事件省略的 ui 对象.该对象拥有三个定义弹出窗口位置的属性ui.xui.yui.positionTo.

后一个property的默认值是window,它会覆盖任何先前添加到ui.xui的值.y.因此,每当 popupafterposition 触发时,ui.positionTo 应该更改为 null 而不是 window.

以下代码应包含在 pageinit 事件 (2) 中.

$(document).on("pageinit", function () {$("#popup_ID").on("popupbeforeposition", function (e, ui) {ui.x = 值;/* (1) */ui.y = 值;ui.positionTo = null;/* 这个 */});});

<块引用>

演示

(1) 值 = 数

(2) pageinit 是一个特殊的 jQM 事件,它等效于 .ready() 并且应该使用它来代替它.

In PC browser there is a problem that popup changes its position on window resizing. I googled it and found that JMF has a bug changing positionTo from origin/#codeSource to window.

In mobile browser I have the same issue on page scrolling. Popup is rendered again in wrong position.

I need either to set somehow correct position or to avoid multitime reopening on window resizing and page scrolling.

Could somebody give me a piece of advice?

解决方案

You need to listen to popupbeforeposition event and alter ui object which that event omits. The object holds three properties which define popup's position, ui.x, ui.y and ui.positionTo.

The default value of the latter property is window, and it overrides any previously added values to ui.x and ui.y. Hence, whenever popupafterposition fires, ui.positionTo should be changed to null instead of window.

Edit: The below code should be wrapped in pageinit event (2).

$(document).on("pageinit", function () {
  $("#popup_ID").on("popupbeforeposition", function (e, ui) {
      ui.x = value; /* (1) */
      ui.y = value; 
      ui.positionTo = null; /* this */
  });
});

Demo

(1) value = number

(2) pageinit is a special jQM event which is equivalent to .ready() and should be used instead of it.

这篇关于Jquery 移动弹出窗口在页面调整大小或滚动时在错误的位置重新打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-23 08:53:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1038474.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弹出窗口   大小   错误   位置   页面

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!