Say I display a div through using jQuery, but I want the rest of the window (everything except that div) be unaccessible for user - so all the controls are disabled and the user can only do something with the controls in that special div?
-
demos are here jquery.malsup.com/block/#demoskobe– kobe2010-12-07 19:46:41 +00:00Commented Dec 7, 2010 at 19:46
-
as i said simple fix can be z-index///kobe– kobe2010-12-07 19:47:17 +00:00Commented Dec 7, 2010 at 19:47
-
I think you are looking for an expose effect.Josiah Ruddell– Josiah Ruddell2010-12-07 19:48:14 +00:00Commented Dec 7, 2010 at 19:48
-
I used fancybox. here it is fancybox.netAsim Zaidi– Asim Zaidi2010-12-07 20:18:02 +00:00Commented Dec 7, 2010 at 20:18
-
@everyone - thank you for all the answers, all the samples are great. So giving +1 to everyone!dexter– dexter2010-12-08 18:26:33 +00:00Commented Dec 8, 2010 at 18:26
4 Answers
You can build a modal dialog from your <div> element:
$("#yourDivID").dialog({ modal: true });
3 Comments
Please use jquery bock UI plugin
http://jquery.malsup.com/block/
for a simple fix , if your z-index of popup is greater than all the elements behind , you cannot touch the items behind
give z-index like 1000 or so
Comments
Rather than using full blown plugins for something that is so simple:
Use a second div, whose css position is fixed and whose width and height is equal to the window.innerHeight & window.innerWidth properties respectively. Set the z-index to something large, but less than the z-index of the model dialog your showing.
$('<div />').css({
position: 'fixed',
left: 0,
top: 0,
width: window.innerWidth,
height: window.innerHeight,
'z-index': 1000
});
As mentioned in the comments however, this does not stop the users tabbing to the hidden fields; to do that, you can bind an event to capture the tab press, and cancel it:
$(document).bind('keydown', function (event) {
if (event.which === 9 && !$(event.target).closest('.model').length) {
event.preventDefault();
}
});
To give you the ability to add/ remove the event handler at will, it will be easier to do it like so:
function stopTab(event) {
if (event.which === 9 && !$(event.target).closest('.model').length) {
event.preventDefault();
}
}
$(document).bind('keydown', stopTab); // to add
$(document).unbind('keydown', stopTab); // to remove
Your modal dialog must have a class of modal for this to work (or simply alter the selector).