How to check if jQM popup fits user's viewport?

此生再无相见时 提交于 2020-01-15 16:47:55

问题


So I've managed to add scrollbars to large jQM popups with css('overflow-y', 'scroll'). But how to do this only when the popup is larger than the user's viewport?

I'm trying with the jquery-visible plugin but I can't get it to respond:

http://jsfiddle.net/mmRnq/124/

$('#test-button').on('click', function(e) {     
  $('#confirmDialog').popup('open');

  // https://stackoverflow.com/questions/20791374/jquery-check-if-element-is-visible-in-viewport  

  if(!$('#confirmDialog').visible(true)) {
    alert('Popup not fully visible - add overflow scrolling');
    $('#confirmDialog').css('overflow-y', 'scroll'); 
  }  
});

回答1:


You can use

overflow-y: auto

This makes the scrollbar only visible when it is needed.

Updated FIDDLE

UPDATE:

You can also just make the content of the popup scrollable so the titlebar remains in view:

#confirmDialog .ui-content {
    overflow-y: auto;
}

$('#confirmDialog').on({
  popupbeforeposition: function() {
      var maxHeight = $(window).height() - 120;
      $('#confirmDialog .ui-content').height(maxHeight);
  }
});

DEMO



来源:https://stackoverflow.com/questions/22894479/how-to-check-if-jqm-popup-fits-users-viewport

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