切換到另一個頁面後,地圖的包含元素樣式會發生變化,正如您所看到的,它不會那樣。捕獲每次顯示頁面時觸發的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