Custom div modal

Custom div modal using jquery

by santosh_patnala

HTML

<a href="javascript:void(0);" id="launchModal" class="custom_modal">Launch Modal</a>
    <div id="modalBackground"></div>


    <div id="modalArea">
        <div class="modalWrapper">
            <header id="modalHeader">
                <h3>Header part</h3>
                <span class="modalClose">X</span>
            </header>
            <section id="modalContentArea">Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum.</section>

            <div class="push"></div>
        </div>
        <footer id="modalFooter">
            <h6>footer</h6>
        </footer>
    </div>

CSS

a {
            text-decoration: none;
            color: #6b3609;
        }

        .custom_modal {
            background-color: #ed883c;
            display: block;
            padding: 4px 8px;
            text-align: center;
            width: 120px;
        }

            .custom_modal:hover {
                background-color: #db6a16;
                transition: ease-in-out background-color 0.5s;
            }

        #modalBackground {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: black;
            opacity: .50;
            -webkit-opacity: .5;
            -moz-opacity: .5;
            filter: alpha(opacity=50);
            z-index: 1000;
        }

        #modalArea {
            background-color: white;
            border-radius: 10px;
            -webkit-border-radius: 10px;
            -moz-border-radius: 10px;
            box-shadow: 0 0 20px 0 #222;
            -webkit-box-shadow: 0 0 20px 0 #222;
            -moz-box-shadow: 0 0 20px 0 #222;
            display: none;
            height: 240px;
            left: 50%;
            margin: -120px 0 0 -160px;
            padding: 10px;
            position: absolute;
            top: 50%;
            width: 320px;
            z-index: 1000;
        }

            #modalBackground.active, #modalArea.active {
                display: block;
            }


        * {
            margin: 0;
        }

        html, body {
            height: 100%;
        }

        footer#modalFooter, .push {
            height: 23px; /* .push must be the same height as .footer */
        }

        .modalWrapper {
            min-height: 100%;
            height: auto !important; /* This line and the next line are not necessary unless you need IE6 support */
            height: 100%;
            margin: 0 auto -23px; /* the bottom margin is the negative value of the footer's height */
...

JavaScript

$(function () {
    $("#launchModal, #modalBackground, #modal_close,.modalClose").click(function () {
                $("#modalArea,#modalBackground").toggleClass("active");
            });
});