Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a modal dialog - content disappearing
    primarykey
    data
    text
    <p>I am trying to make a jquery modal dialog. (please do not say "use a plugin").</p> <p>I am well aware that the js I am using is crap, once I am trying to hack together the basic functionality, once I have the basic functionality down I will rewrite this as a jquery plugin for my own use.</p> <p>Anyway,</p> <p>I have got the dialog appearing, and it is in the center of the page, The dialog is sized by its content.</p> <p>In this specific example the content has a fixed width.</p> <p>I am trying to handle the case where the content is bigger that the page width.</p> <p>I am getting a strange issue where, if the page is resized the content seems to literally just be cut off, no scroll bars.</p> <p>What could be my issue?</p> <p><strong>Example:</strong> <a href="http://jsbin.com/egowo3/edit" rel="nofollow">http://jsbin.com/egowo3/edit</a><br> <strong>CSS:</strong> </p> <pre><code>body { padding: 0; margin: 0; color: #fff; } #overlay { position:fixed; width:100%; height:100%; background: rgba(0,0,0,0.8); z-index: 9999; display: none; } #dialog { display: none; background: #000; border: 1px solid #0000ff; position: fixed; z-index: 99999; } #test { display: none; width: 1300px; } </code></pre> <p><strong>Javascript</strong> </p> <pre><code>$(function(){ $('button').click(function(){ var body = $('body'); var content = $('#test'); var dialog = $('&lt;div id="dialog"&gt;&lt;/div&gt;'); var overlay = $('&lt;div id="overlay"&gt;&lt;/div&gt;'); var width = content.outerWidth(true); var height = content.outerHeight(true); body.prepend(dialog); body.prepend(overlay); dialog.prepend(content) .height(height) .width(width); content.show(); var left = (overlay.width()/2)-(dialog.outerWidth()/2); var top = (overlay.height()/2)-(dialog.outerHeight()/2); dialog.css({ left : left, top : top }); overlay.fadeIn('fast'); dialog.fadeIn('fast'); $(window).resize(function() { overlay = $('#overlay'); dialog = $('#dialog'); if(overlay.length == 0 || dialog.length == 0) return false; var left = (overlay.width()/2)-(dialog.outerWidth()/2); var top = (overlay.height()/2)-(dialog.outerHeight()/2); dialog.css({ left : left, top : top }); }); }); }); </code></pre> <p><strong>HTML</strong></p> <pre><code>&lt;body&gt; &lt;button&gt;Modal Me&lt;/button&gt; &lt;div id="test"&gt; &lt;p&gt;Pid ac lundium urna tempor vut, elementum adipiscing mauris, magna cum odio! Urna pulvinar, et egestas magna diam mus porttitor natoque urna nisi turpis amet sed, etiam penatibus, nascetur cras lectus auctor? Nisi, elementum ac dictumst facilisis nec elementum ac? Placerat adipiscing? Dis montes cursus sagittis etiam et tortor ridiculus.&lt;/p&gt; &lt;p&gt;Nisi nec mid? Enim amet, enim rhoncus nisi penatibus nec, natoque amet placerat in in? Scelerisque magna, aliquam elit habitasse turpis parturient et facilisis urna adipiscing, porta hac nunc, sit pellentesque! In enim? Mus nunc risus amet sed tincidunt, hac placerat placerat diam, et et, sociis mid. Pellentesque, vel.&lt;/p&gt; &lt;/div&gt; &lt;/body&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload