So I have created a modal in bootstrap in inside this first modal a place a button for opening a second modal. It works perfectly . But when i close the 2nd modal the first modal scroll doesn't work. Rather if i scroll then the main body scrolled. So How can i solve this.
Add to your jQuery Code
<script>
$('#id_ofyou_secondary_modal').on('hidden.bs.modal', function (e) {
$('body').addClass('modal-open');
});
</script>
Related
How do I close bootstap modal programmatically? I checked so many answers about it, but none of them work... All below methods close modal, but keeps backdrop of it so I tried to remove backdrop with $('.modal-backdrop').remove(); it breaks modal and if I show it after removing backdrop scroll doesn't work on modal. I need to close it through js and whenever I want to by calling method. I know I can use data-dismiss="modal" to close it.
how I'm hiding modal:
$('#mymodal').modal("toggle");
$('#mymodal').modal("hide");
$('.close').click();
Update
So I see that for a lot of people it works with $('#mymodal').modal("hide"); but when I Inspect page I can see that there is two modal-backdrops in the body and after I call hide it closes modal and first modal-backdrop, but second one stays and this is why it's not working.
with modal open:
After closing modal with $('#mymodal').modal("hide");
This should work. if not you have other problem in code. Read modal javascript docs https://getbootstrap.com/docs/4.0/components/modal/#via-javascript
$('#myModal').modal('hide')
Actually I got the popup modal fancy box problem where the popup is not loaded the content properly. The modal div is by default to display none. And I need to show that modal on click event.
I am using the module for AfterPAy payment method where this feature is included. When We click on the learn more button then the popup is open but not the content in that fancy box. I need to make it perfect. This my website URl https://www.tradie.com/tradie-honey-badger-sports-mid-length-trunk-1371.html
(function($) {
$(document).on('ready', function() {
$('.afterpay-what-is-modal-trigger').fancybox({
afterLoad: function() {
$('#afterpay-what-is-modal').css("display", "block");
}
afterShow: function() {
$('#afterpay-what-is-modal').find('.close-afterpay-button').on('click', function(event) {
event.preventDefault();
$.fancybox.close();
})
}
})
});
})(jQuery);
The above js code is in the file of extension modal.js. Here the aftershow function is working, but afterload is not working. Please how that modal will open properly with content.
Thanks.
As per the concern there is a div that is inline set to display none. So when you will hit the link/button then the modal will blanks due to that inline css.
Please find the html of the modal file and add an extra div at the top of that code and set display none to that div inline.
e.g.,
<div style="display:none;">
<div id="afterpay-what-is-modal">
<!--some modal code for popup-->
</div>
</div>
Add a div before the and style it to display none inline that it.
Hope this will work for you.
I've been searching SO and the Web for an answer on my issue, but couldn't find anything.
I have appended a reveal modal to the BODY with jQuery. Now when I click on the button which opens the modal, only the overlay is shown. I just can't figure out what is causing the problem.
I have created an example on codepen. http://www.codepen.io/anon/pen/KhsGH
"Open Modal 1" should open the programmatically appended modal.
"Open Modal 2" opens the modal, that is placed directly in the BODY. (This one is just to show that it usually works)
Maybe one of you guys can help me with this.
Thank you very much.
EDIT:
This error is displayed in Firebug:
TypeError: settings is undefined
this.show(modal, settings.css.open);
You have to call foundation after you have appended the modal content div
$(document).ready(function(){
$("body").append('<div class="reveal-modal small foo1" data-reveal><p>Test Reveal</p></div>');
$(document).foundation();
$(document).on('click', '.trigger_foo1',function(e){
e.preventDefault();
$(".foo1").foundation('reveal', 'open');
});
$(document).on('click', '.trigger_foo2',function(e){
e.preventDefault();
$(".foo2").foundation('reveal', 'open');
});
});
I'm having problems getting the SimpleModal jQuery plugin to close when the body is clicked. So far, only the 'X' button works to close it with:
$('a.modalCloseImg').hide();
Here is my code for launching the modalbox. Note that #login-link is the link that opens the box and #login-form is the hidden modal box.
// launch modal box
$("#login-link").click(function(){
$("#login-form").modal();
});
I've tried adding
$("#login-form").modal(overlayClose:true);
but it doesn't seem to be working. (FYI that parameter is per the documentation of the SimpleModal box as seen here.
Try launching the modal box with an additional parameter, like this:
// launch modal box
$("#login-link").click(function(){
$("#login-form").modal({ overlayClose: true });
});
you forgot additional {}.
I'm successfully using Simple Modal to launch a modal when a button is clicked, however, I want the page to scroll to the top first. I tried placing an anchor tag at the top of the page and referencing it in my link using , but it didn't work. The Simple Modal still worked, but it didn't scroll to the top of the page first. Is there a way to edit the simple modal javascript to make it first scroll to the top of the page before the modal is opened?
use JavaScript before you call your modal: window.scrollTo(0,0)
Use a callback: http://www.ericmmartin.com/projects/simplemodal/#options
$('#modalContent').modal({
onOpen: function () {
$('html, body').scrollTo(0, 0);
}
});