javascript - How to make sure that a jQueryUI-Dialog's "X"-Button stays on Screen? -


please consider following codepen: https://codepen.io/chrisvomrhein/pen/yzbwaz

when click button, dialog huge amount of text opened ,

$( "#dialog" ).dialog("option", "position", {      my: "right top",      at: "right top",      of: $(this)  }); 

makes sure positioned relative button. 3 buttons on top, works nicely. jquery makes sure dialog stays on screen.

jquery ui dialog scenario 1

even top left button jquery smart enough shift dialog stays on screen.

jquery ui dialog scenario 2

however, click 1 of buttons positioned @ bottom, jquery shifts dialog; upwards time. problem x-button (that closes dialog) no longer reachable. also, there not scrollbar showing up!

jquery ui dialog scenario 3

is there way force jquery ui make sure x inside accessible area of browser window? or missing basic here?

to make sure dialog smaller window can set height retrieving jquery , passing parameter this:

$( "#dialog" ).dialog({ autoopen: false, height: $(window).height()* 0.9 }); 

in case height retrieved window, can search container element or else want dialog fit in. height multiplied 0.9 make bit smaller page.

using css property overflow:auto can make scroll bar appear when text bigger dialog,

look @ codepen

edit

i understood problem, changed code: codepen
solution set dialog size max dimension possible checking max between space top , bottom:

$(".opener").click(function() {   //get button position   var pos = $(this).position();   //max between top , bottom   var h = math.max($(window).height()* 0.9 - pos.top, pos.top * 0.9  );   $( "#dialog" ).dialog({       position: {            my: "right top",            at: "left bottom",            of: $(this)         },        autoopen: false,         height: h   });   $( "#dialog" ).dialog("open"); }); 

hope helps!


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -