jQuery mobile panel open scrolls page to the top, how to change this?

前端 未结 4 1597
误落风尘
误落风尘 2021-01-07 01:43

So I\'m developing a jQuery mobile phonegap app and I noticed that every time I open the panel the main page scrolls to the top automatically. I want the page to remain at t

4条回答
  •  感动是毒
    2021-01-07 02:14

    I've recently encountered this and come up with the following solution.

    1.- When user clicks Menu link, run a function called menuOpen

    function menuOpen(){
        var scrollTop = window.document.body.scrollTop;
    
     //You can replace this with a regular menu open. I use some code that places the same menu panel on every page so that I only have to write it once, but it causes a duplicate ID of "menupanel"- hence the code that will only open #menupanel on the current active page
        $.mobile.activePage.find('#menupanel').panel("open");
    
        window.document.body.scrollTop = scrollTop;
    }
    

提交回复
热议问题