Bootstrap navbar disappears using leaflet

我的梦境 提交于 2019-12-10 19:19:35

问题


I am having some difficulty integrating leaflet with Bootstrap. I am using a script that creates a collapsible left navbar. When I interact with the leaflet map, the bootstrap navbar disappears.

This seems to be a CSS conflict, but I can't seem to identify where to begin troubleshooting. Here is the jsfiddle followed by CSS: http://jsfiddle.net/6sSrE/. Notice that when clicking the map, the navbar disappears.

It would be helpful if another set of eyes could suggest a different direction to identify this problem. I would really like to use Bootstrap for this application, but I can't resolve the conflict.

html, body, #map {
height: 100%;
margin: 0;
}
   body .viewport {
  position: absolute;
  padding: 0;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
}

body .viewport .frame {
  position: absolute;
  width: 200%;
  height: 100%;
  top: 0;
  bottom: 0;
  left: 0; 
  padding: 0;
}

body .viewport .frame .navbar .navbar-inner {
  border-radius: 0;
  padding-left: 5px; 
}

body .viewport .frame .menu {
  height: 100%;
  /* background-color: #3D6AA2; */ 
}

body .viewport .frame .menu.collapse {
  float: left;
  height: 100% !important;
  width: auto; 
}

body .viewport .frame .menu.collapse.height {
  position: relative;
  height: 0;
  overflow: hidden;
  -webkit-transition: height 0.35s ease;
  -moz-transition: height 0.35s ease;
  -o-transition: height 0.35s ease;
  transition: height 0.35s ease; 
}

body .viewport .frame .menu.collapse.width {
  position: relative;
  width: 0;
  overflow: hidden;
  -webkit-transition: width 0.35s ease;
  -moz-transition: width 0.35s ease;
  -o-transition: width 0.35s ease;
  transition: width 0.35s ease; 
}

body .viewport .frame .menu.collapse.in.width {
  width: auto; 
}

body .viewport .frame .menu.collapse.in.height {
  height: auto; 
}

body .viewport .frame .menu .collapse-inner {
  position: relative;
  width: 250px;
  height: 100%; 
}

body .viewport .frame .menu .navbar .navbar-inner {
  text-align: center;
  color: grey;
  font-size: 1.2em;
  line-height: 38px; 
}

body .viewport .frame .menu .nav-stacked {
  padding: 0 10px; 
}

body .viewport .frame .view {
  width: 50%;
  height: 100%;
  overflow: hidden; 
}

body .viewport .frame .view .navbar .navbar-inner .btn-navbar {
  display: block;
  float: left; 
}

body .viewport .frame .view #map {
  margin: auto 15px;
  text-align: justify; 
}

回答1:


It looks like every time the map gets focused the webpage is moving 78 pixels down. (You might be able to find where this is happening and fix it.)

However I just came up with something quick that would adjust your navbar so that it would show up at the top of the page every time.

$(document).ready(function(){
    var margin = 78;
    $('#map').on('mousedown',function(){
        $('#navBar').css('margin-top',margin+'px');
    });  
    $('#map').blur(function(){
        margin = margin+78;
    }); 
});

Note: I also added a ID to your nav bar.

<div class="navbar navbar-inverse" id="navBar">

Here is an example, seems to work pretty good for now, but might be worth your time later to figure out why the page is being moved down.

http://jsfiddle.net/6sSrE/15/



来源:https://stackoverflow.com/questions/19104516/bootstrap-navbar-disappears-using-leaflet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!