Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically close an open jquery.reveal.js modal box?

I am using the Reveal jQuery plugin. http://www.zurb.com/playground/reveal-modal-plugin

I need to programmatically close the model box when I am done with it, however that feature is not including directly with the plugin.

According to Dave in the comments page,

"The code is in there, just need to hook it up to be called programmatically."

like image 631
TJ McKenzie Avatar asked Feb 03 '11 09:02

TJ McKenzie


3 Answers

If your modal's id is 'reveal-modal', then just this line will do it:

$('#reveal-modal').trigger('reveal:close'); 
like image 119
Silas Snider Avatar answered Sep 21 '22 17:09

Silas Snider


You can do it a couple of ways.

Trigger a click via jquery on the dismissmodalclass element (defaults to 'close-reveal-modal')

 $('.close-reveal-modal').click();

OR

Add this to reveal.js

$.fn.hideModal = function(options){
  var self        = this,
      modal       = $(self),
      topMeasure  = parseInt(modal.css('top'));
  $('.reveal-modal-bg').css({'display' : 'none'});      
  modal.css({'visibility' : 'hidden', 'top' : topMeasure});
}

and use

$('#your_modal_box').hideModal()
like image 36
Cory Avatar answered Sep 24 '22 17:09

Cory


The modals class is usually 'reveal-modal'. so changing the lookup to be class based rather than id based, makes this work for more cases:

$('.reveal-modal').trigger('reveal:close');
like image 27
Paul Millsaps Avatar answered Sep 22 '22 17:09

Paul Millsaps