切换到另一个页面后,地图的包含元素样式会发生变化,正如您所看到的,它不会那样。捕获每次显示页面时触发的pagecontainershow
事件,检查它是否为您的地图页面,然后调用地图实例的invalidateSize
方法,以便更新您的地图。这应该够了吧。
// Attach event handler to pagecontainershow event
// This will execute every time a page is shown/ready
$(document).on('pagecontainershow', function(e, ui) {
// Get the id of the currently active page
var pageId = $('body').pagecontainer('getActivePage').prop('id');
// Check if the id matches the id of your map's page
if (pageId == 'id_of_your_map_page') {
// It's a match, invalidate the map so it resets
map.invalidateSize();
// Assuming 'map' holds a reference to your map instance
}
});
https://api.jquerymobile.com/pagecontainer/#event-show
http://leafletjs.com/reference.html#map-invalidatesize
来源
2015-09-04 12:30:47
iH8
啊确定,但我只是有一个数据的rel =“后退”按钮返回到我的主页..你说我应该使用show事件的功能? – ayasha
我已经添加了一些代码来澄清事情。希望有帮助 – iH8
哇,它真的有用!非常感谢!! – ayasha