如何在 jQuery Mobile 中检测/查询当前正在进行的页面更改/转换?

发布于 2024-11-09 00:59:11 字数 129 浏览 0 评论 0原文

如何检测/查询 jQuery Mobile (jQM) 中当前是否正在进行页面更改/转换?

我的目标是防止在页面之间切换时打开对话框。目前,当页面更改事件正在进行时打开对话框时,UI 会中断。

对此有什么想法吗?

How can I detect/query, whether a changepage / transition is currently ongoing in jQuery Mobile (jQM)?

My goal is to prevent opening a dialog when a switch between pages is currently happening. Currently, th UI breaks when a dialog opens while a changepage event is ongoing.

Any Ideas on that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我三岁 2024-11-16 00:59:11

在 JQM 1.4.0 中,ui-mobile-viewport-transitioning 类在转换期间添加了 body 标记,因此以下内容对我有用:

if (!$("body.ui-mobile-viewport-transitioning").length) {
   //do something
}else{
    console.log("Don't do it we are transitioning")
    return false
 }

In JQM 1.4.0 the class ui-mobile-viewport-transitioning is added the body tag during transitions so the following works for me:

if (!$("body.ui-mobile-viewport-transitioning").length) {
   //do something
}else{
    console.log("Don't do it we are transitioning")
    return false
 }
云裳 2024-11-16 00:59:11
  • pagebeforeshow

在正在显示的页面上、转换开始之前触发。

  • pagebeforehide

在页面被隐藏、转换开始之前触发。

  • pageshow

在转换完成后正在显示的页面上触发。

  • pagehide

在页面转换完成后被隐藏时触发。

http://jquerymobile.com/demos/1.0a4.1/ #docs/api/events.html

  • pagebeforeshow

Triggered on the page being shown, before its transition begins.

  • pagebeforehide

Triggered on the page being hidden, before its transition begins.

  • pageshow

Triggered on the page being shown, after its transition completes.

  • pagehide

Triggered on the page being hidden, after its transition completes.

http://jquerymobile.com/demos/1.0a4.1/#docs/api/events.html

源来凯始玺欢你 2024-11-16 00:59:11

我没有在 jQuery Mobile 中找到过渡状态信息,但是您可以简单地添加三个事件,一个在更改之前,一个在更改之后,一个在页面更改失败时添加。然后,将当前是否发生转换保留在全局变量中:

window.transitioning = false;

$(document).on("pagebeforechange", function() { transitioning = true; });
$(document).on("pagechange", function() { transitioning = false; });
$(document).on("pagechangefailed", function() { transitioning = false; });

在本例中,我创建了一个全局变量 transitioning 但您可以在您认为合适的位置创建此变量,例如在对话框中创建一个局部变量处理程序而不是使用全局变量。

您现在可以像这样添加您的条件:

if(!transitioning) {
  // Do your stuff
} else {
  // Delegate the events by listening for pagechange and then do your stuff
}

I didn't find transition state information within jQuery Mobile, however you can simply add three events, one before and one after the change and one for when the page change has failed. Then, keep in a global variable whether a transition is currently occuring:

window.transitioning = false;

$(document).on("pagebeforechange", function() { transitioning = true; });
$(document).on("pagechange", function() { transitioning = false; });
$(document).on("pagechangefailed", function() { transitioning = false; });

In this example, I create a global variable transitioning but you could create this variable where you see fit, e.g. making a local variable in your dialog handler rather than using a global variable.

You can now add your condition like this:

if(!transitioning) {
  // Do your stuff
} else {
  // Delegate the events by listening for pagechange and then do your stuff
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文