Thursday, May 5, 2011

How to create a modal popup using javascript and CSS

Actually, two questions:

  • How can I create a modal popup with background color of gray?
  • Also I need to create for a cover background color only to table itself. Not to overall page.

How do I do this using javascript and css?

Thanks & Regards

Ravi

From stackoverflow
  • How about this: Modal-style pop-ups in JavaScript

  • Here is the HTML, which should probably be inserted with JS, and the styles should be in an external stylesheet.

    <div style="background: gray; width: 200px; height: 200px; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px" id="modal">I'm a modal</div>
    

    Then, you could leverage jQuery to display it.

    $('a.modal').bind('click', function(event) { 
        event.preventDefault();
        $('#modal').fadeIn(800);
    });
    

    Funny thing is, when I was typing that HTML in, an actual modal box with a gray background appeared!

    This is only a start, you'll want to learn from this and build upon it. For example, the script should check is(':hidden') and show, and if not then fadeOut(800) or similiar.

  • I use this for the mask that sits on top of the screen

    .Mask { display: none; width: 100%; height: 100%; z-index: 9000; padding: 0px; margin: 0px; background: transparent url(mask.png); position: fixed; top: 0px; overflow: hidden; }

  • Go Jquery, go jquery, go jquery:

    http://www.84bytes.com/2008/06/02/jquery-modal-dialog-boxes/

    RSolberg : Sounds a bit like an Inspector Gadget Reference. Go Go jQuery Modal...
    jcollum : I was thinking of Futurama when I wrote it: "Go Bender, go Bender, go Bender!"

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.