Jquery simplemodal close an existing modal and open a new one?

Well, thatโ€™s why all modals already have an image in the upper right corner to close them. How can I make another anchor to do the same? I thought I could use the "closeClass" option, which by default is "simplemodal-close" and simply adds this class to the anchor, but did not have the desired effect. Is that what I have to do? In addition, all modals will have a โ€œcontact usโ€ link, which should close her own modal and open a contact modal. How can I wait until it is closed to open the next one?

Ideas?

$('a#ask').click(function(){ $.modal.close(function(){ }); $('#modal-contact').modal(); }); 
+4
source share
4 answers

1) If you assign simplemodal-close element that is in the contents of the dialog, SimpleModal will automatically attach a close function to the click event for that element.

2) There are several ways to do this, either by replacing the contents, or by first closing the dialog with $ .modal.close (); then a new one opens.

UPDATE

 $('a#ask').click(function(){ $('#modal-contact').modal({onShow: function (dialog) { // handle the close yourself. // Don't use the closeClass on this element // call $.modal.close(); when you are done // call a function to open a new modal }); return false; }); 
+3
source

The current onClose event acts like onBeforeClose, not onAfterClose for $ .modal.close (). The only workaround is to wait:

.

$ modal.close (); window.setTimeout (showSecondModal, 500);

+2
source

To answer the second question - how to close an existing modal and subsequently open a new one, you need to do three things:

  • Add Persist: true to the callback option of the first modal file. According to Eric Martin: โ€œIf true, data will be maintained between modal calls; if false, data will be returned to its original state.
  • Add the onClose callback to the first modal module.
  • Close the first modal BEFORE the function starts to open the second modal.

So, when you close modal with $. modal.close () is started by onClose , thereby starting the animation and closing the modal. Since persist is true, the next function will be saved . Your function will work, and the second mode will open.

 $("#first_modal").modal({ containerId: 'modal_id', persist: true, onClose: function (dialog) { dialog.container.fadeOut(100, function () { dialog.overlay.fadeOut(200, function(){ $.modal.close(); showSecondModal(); }); }); 

}});

+1
source

Upgrading to the latest version of SimpleModal, currently 1.4.4. The timeout error was fixed in 1.4.2 in accordance with http://www.ericmmartin.com/simplemodal-1-4-3-released/ :

Removed opera operating mode for close () function causing problems

Your code above, with slight modifications, should work as expected:

 $('a#ask').click(function(){ $.modal.close(); $('#modal-contact').modal(); }); 
+1
source

Source: https://habr.com/ru/post/1308100/


All Articles