Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable whole body other than a div


I have a div which is creating through ajax, i would like to disable the whole body once the div is popup and until, unless the div is closed.
Is this possible in jquery. Please let me know your suggestion

Thanks,
Praveen Jayapal

like image 526
praveenjayapal Avatar asked Sep 22 '10 09:09

praveenjayapal


People also ask

How do you stop an entire page in HTML?

The basic technique for this is to add a 100% width and height div on top of everything. $('body'). append('<div class="cover"/>'). css({ position: 'absolute', height: '100%', width: '100%', zIndex: '999' });

How do I stop div clicking?

To disable clicking inside a div with CSS or JavaScript, we can set the pointer-events CSS property to none . Also, we can add a click event listener to the div and then call event. preventDefault inside.


4 Answers

You want to REMOVE, or hide the body? Technically this shouldn't be possible because you need to append the div to the body in order to see it. What you could do is create a 'mask' layer that covers the WHOLE body, then use z-index for your div to display it on top of the body.

Something like:

http://www.queness.com/post/77/simple-jquery-modal-window-tutorial

might help!

To completely hide the page all you would need to do is change line 21:

$('#mask').fadeTo("slow",0.8);

in the javascript to:

$('#mask').fadeTo("slow",1);

and the color of the mask on line 7 of the CSS can be changed to whatever you want too:

background-color: #000;

like image 178
Alex Avatar answered Oct 01 '22 12:10

Alex


That should do the trick..

HTML:

<body>
    <div id="overlay">
        this is above the body!
    </div>
<!--...rest...-->
</body>

CSS:

#overlay {
    background-color: #ccc; /*or semitransparent image*/
    display: none;
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 100;
}
#ajax-div {
    z-index: 200; /*important, that it is above the overlay*/
}

Javascript:

<script type="text/javascript">
$(document).ready(function() {
    //your ajax-call
    $.ajax({
        //on success
        success: function() {
            //your logic your showing the ajax-div
            $('#overlay').show(); //or fadeIn()
        }
    })

    //use live to catch the close-click of the later added ajax-div
    $('#ajax-div a#close').live('click', function() {
        //close the ajax-div
        $(this).parent().hide();
        //close the overlay
        $('#overlay').hide(); //or, again, fadeOut()
    });
});
</script>
like image 35
Tim Avatar answered Oct 03 '22 12:10

Tim


What it sounds like you want is something known as a modal dialog box.

There are a number of JQuery scripts to achieve this quite easily. Here are some links for you:

  • http://choosedaily.com/1178/15-jquery-popup-modal-dialog-plugins-tutorials/

  • http://plugins.jquery.com/project/modaldialog

  • http://www.queness.com/post/77/simple-jquery-modal-window-tutorial

Hope that helps.

like image 36
Spudley Avatar answered Sep 30 '22 12:09

Spudley


OK ... best idea is use jquey.ui if you use jquery.

http://jqueryui.com/demos/dialog/#modal

You can choose theme and download only components you like..

Then just include js and css a place img folder and call dialog. It is quiet easy...

like image 21
jatt Avatar answered Oct 01 '22 12:10

jatt