changePage “jumps” back to old page

后端 未结 6 1992
长情又很酷
长情又很酷 2020-12-15 18:47

I\'ve a big problem with a jQuery Mobile Application: I\'m using custom functions (they are triggered by onClick) to switch the page with currentPage.

It only happen

6条回答
  •  感情败类
    2020-12-15 18:58

    After trying for weeks to find a solution to this, I ended up doctoring the JQM library to disable page transitions one right after another. It's not a good solution, but it's the only thing I could get to work.

    I was getting pages jumping back on both $.mobile.changePage and on anchor links. I used the slide transition, but removing it did not fix the problem. Setting pushStateEnabled to false did not work either. The jumps were happening on all devices and browsers (that I tested, anyway).

    So here's what I did to the JQM library (v1.3.2).

    Before the $.mobile.changePage function is defined, I added:

    var justChangedPage = false;
    

    Then within the function there's a line that goes:

    if ( pbcEvent.isDefaultPrevented()) {
        return;
    }
    

    which I changed to:

    if ( pbcEvent.isDefaultPrevented() || justChangedPage) {
        return;
    }
    

    Then right after this part of the $.mobile.changePage function:

    if ( toPage[ 0 ] === $.mobile.firstPage[ 0 ] && !settings.dataUrl ) {
        settings.dataUrl = documentUrl.hrefNoHash;
    }
    

    I added:

    justChangedPage = true;
    setTimeout(function() {
        justChangedPage = false;
    }, 500);
    

    (Putting that earlier in the function didn't work -- all that stuff executes more than once within a single page transition. And half a second seemed to be the minimum timeout that prevented the page jumps.)

    I hope this helps someone even if it is a hack...

提交回复
热议问题