无法为openlayers地图设置地图的div高度 [英] Cannot set map's div height for openlayers map
本文介绍了无法为openlayers地图设置地图的div高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码使地图的div宽度最大,但高度变为0(%值无关紧要,始终为0)
This code make the map's div width max but height to 0 (the % value doesn't matter, it's always 0)
<div id="map" style="width: 100%; height: 100%;"></div>
这可行,因为它将地图的div设置为固定大小,但显然不是我想要的.
This works, as it sets the map's div to a fixed size, but is obviously not what I want.
<div id="map" style="width: 100%; height: 500px;"></div>
有人经历过吗?有人建议如何解决这个问题吗?
Has someone experienced this? Anyone a suggestion on how to fix this?
我也在使用jquery(-mobile)
I'm also using jquery(-mobile)
谢谢
推荐答案
这是我的解决方法:
function fixContentHeight(){
var viewHeight = $(window).height();
var header = $("div[data-role='header']:visible:visible");
var navbar = $("div[data-role='navbar']:visible:visible");
var content = $("div[data-role='content']:visible:visible");
var contentHeight = viewHeight - header.outerHeight() - navbar.outerHeight();
content.height(contentHeight);
map.updateSize();
}
这篇关于无法为openlayers地图设置地图的div高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文