Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a very basic version:</p> <pre><code>$("&lt;iframe id='shim' src='http://jsbin.com/abira4'&gt;").css({ width: "100%", height: "100%", position: "absolute", left: "0px", top: "0px", zIndex: "100", backgroundColor: "#fff", opacity: "0.5" }).appendTo(document.body); $("&lt;div&gt;Hi there, click me to dismiss&lt;/div&gt;").css({ zIndex: "101", border: "1px solid black", backgroundColor: "#ecc", position: "absolute", left: "100px", top: "100px" }).appendTo(document.body) .click(function() { $(this).remove(); $("#shim").remove(); }); </code></pre> <p><a href="http://jsbin.com/ocobu4" rel="nofollow">Live example</a></p> <p>How it works:</p> <ul> <li>We create an iframe to act as a shim over the body of the page. This eats any clicks outside the "dialog box" div we add a moment later, and also deals with the issue of OS-rendered controls and flash animations popping to the top. We also make it semi-transparent (in this case, background-color is <code>#f0f0f0</code> and opacity is 50%) so it "greys out" the underlying document. This is absolutely positioned at 0,0 with 100% width and height, and a z-index of 100 (this has to be higher than anything else on the page). The <code>src</code> of the iframe should be a blank document.</li> <li>We then create a div for the "dialog box" which is also absolutely positioned and has a z-index higher than the iframe shim.</li> </ul> <p>Now, there are a <em>lot</em> of variations. For instance, there's no reason at all you can't have the model div markup in the HTML document rather than in the script&nbsp;&mdash; -- just give it <code>display: none</code> until you need it. Things like that.</p> <p>Obviously, this version lets you click anywhere on the dialog box to dismiss it, but it's easily modified to only allow closing with an [X] somewhere. And to say that it could use some styling would be to...put it mildly.</p> <p>All that said, I can't claim it's remotely bulletproof. That's why well-tested plug-ins are for. :-)</p>
    singulars
    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. VO
      singulars
      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