Creating a modal window on page load

0pt1m1z3 picture 0pt1m1z3 · Feb 27, 2015 · Viewed 24.8k times · Source

I am using the Kube framework (http://imperavi.com/kube/) which includes a modal function. Unfortunately the documentation is kind of sparse or I am too dumb (http://imperavi.com/kube/tools/js-modal/).

They have sample code showing how to launch modals on button clicks, but I am trying to launch it on body load. Can anyone with either experience with Kube or a better understanding of JS/JQuery help me do that? I wan to make sure I can specify settings like width and blur.

I know there are many many modal plugins out there, but I am trying to limit my project to just this one framework.

Answer

dowomenfart picture dowomenfart · Feb 27, 2015

This will run on window ready. http://jsfiddle.net/418hmnjy/2/. This uses no libraries Just HTML, CSS and JavaScript.

HTML

<div id="modal">
    <div class="modalconent">
         <h1></h1>

        <p>fasfsdfasfsfsdfsdfsdsffsd</p>
        <button id="button">Close</button>
    </div>
</div>

JavaScript

window.onload = function () {
    document.getElementById('button').onclick = function () {
        document.getElementById('modal').style.display = "none"
    };
};

CSS

#modal {
    position: fixed;
    font-family: Arial, Helvetica, sans-serif;
    top: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 99999;
    height: 100%;
    width: 100%;
}
.modalconent {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    width: 80%;
    padding: 20px;
}