Bootstrap 3 long modal scrolling background on Android

时光怂恿深爱的人放手 提交于 2019-12-06 09:04:49

问题


I have a long modal that doesn't fully display on my android mobile device, the buttons are bellow the bottom of the screen, the modal doesn't scroll at all but the grayish background behind the modal does, is there any css/js trick to lock the background and allow the modal to scroll while this one is displayed ?


回答1:


This was supposed to be fixed with Bootstrap 3, but it is not working for me. I was able to fix wit with a combination of -webkit-overflow-scrolling CSS property and setting the max-height of my modal. Since I wanted my modal to fill the whole screen, I had to wire up some javascript to detect mobile devices and the set the max-height of my .modal-content to the viewport height of my device

Here is what I did to solve this using a library called jRespond:

Add this CSS to your modals

@media (max-width: $screen-xs-max) {
  .modal-dialog {
    .modal-content {
      -webkit-overflow-scrolling: touch;
      overflow-y: auto;
    }
  }
}

Add jRespond to your application

https://github.com/ten1seven/jRespond/edit/master/js/jRespond.js

Add the following code to your main.js script

    /* This code handles the responsive modal for mobile */
    var jRes = jRespond([{
      label: 'handheld',
      enter: 0,
      exit: 767
    }]);

    jRes.addFunc({
      breakpoint: 'handheld',
      enter: function() {
        $('.modal-content').css('max-height', $(window).height());
        $(window).on('orientationchange', function () {
          $('.modal-content').css('max-height', $(window).height());
        });
      },
      exit: function () {
        $('.modal-content').css('max-height', "");
        $(window).off('orientationchange');
      }
    });



回答2:


It may because of the modal class position is fixed... Try put the code below to your css file, it's work for me...

@media (max-width: 767px) {
    .modal {
        position: absolute;
        overflow:visible;
    }
    .modal-open {
        overflow:visible;
    }
}


来源:https://stackoverflow.com/questions/17965599/bootstrap-3-long-modal-scrolling-background-on-android

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