I have the same problem that this post. But the solution doesnt work with my project.
I use ASP.NET MVC4 and JQM. I have one JS file loaded in the head section. I have a menu like this :
<a href="#left-panel" id="link-menu" class="ui-panel-animate"></a>
<div data-role="panel" id="left-panel" data-display="push">
<ul data-role="listview">
...
</ul>
</div>
my link menu CSS class :
#link-menu
{
top: 3px;
position: absolute;
background: url("images/icons-36-white.png");
}
It's a image, it position is absolute. So when panel is opened i have to add :
.Menu-decalage {
-webkit-transform: translate3d(272px,0,0);
-moz-transform: translate3d(272px,0,0);
transform: translate3d(272px,0,0);
}
In my JS file i have added :
$(document).on('pagebeforeshow', function () {
$("#left-panel").panel({
beforeopen: function (event, ui) {
$("#link-menu").addClass("Menu-decalage");
},
beforeclose: function (event, ui) {
$("#link-menu").removeClass("Menu-decalage");
}
});
It works when the first page is loaded, not after navigation. I have understood that the code is executed on the first page, and i have tried with :
$.mobile.activePage.find('#left-panel').panel();
but it doesn't work.
I have tried to change
$(document).on('pagebeforeshow', function () {
to
$(document).on('pageinit', function () {
but activePage is undefined.
So if someone can give me a solution : Thank you