I'm building a portfolio webpage and have incorporated W3School's Bootstrap Lightbox.
What I am trying to do now is make when you click outside the image, the modal closes; similar to other lightboxes. I also want to add in navigation by using the arrow keys and escape key.
I have searched Stack Overflow and have found questions similar to what I am asking but I do not understand how to add jquery to do what I want. Other lightbox modals work fine when you click outside the box to close it, but why not here? Thank you in advance.
From Bootstrap's page:
$('#myModal').on('hidden.bs.modal', function (e) {
// do something...
})
What do I put in the // do something..?
Related
I'm building a plugin menu for a Wordpress website using the Divi theme.
I add a class using the following code:
jQuery("#cdBarsicon").click(function () { jQuery(".cdMobileMenu").addClass("cdMobileActive"); });
I noticed while testing on a mobile browser that my menu is closed when scrolling down.
What actually happens is that the window is resized when the mobile browser hides the navigation area.
So I realized that all jQuery class changes are reset after the window is resized.
This is probably normal, but how would I keep the menu visible after resizing the window?
I tried using vanilla javascript instead of jQuery, same problem.
function openMobileMenu() { document.getElementById("cdMobileMenu").classList.add("cdActive"); }
I also tried using css() and show() instead of addClass, same problem. It gets reset.
I'm considering using a cookie but I feel I'm missing a simpler solution.
I'm not sure exactly why but the solution in this case was to use the text block instead of the code block in the Divi builder to add the shortcode that displays my menu.
I have a problem. I made a custom Pop-up using elementor and now added a custom jQuery code for the pop-up menu to close on the menu-item click. I have ordered the Elementor to open via action in elementor and close via the code. Picture of elementor action for popup
The code is following.
<script>
jQuery(function($){
$(document).on('click','.elementor-location-popup .menu-item', function(event){
elementorProFrontend.modules.popup.closePopup({}, event );
});
});
</script>
The problem is, that every click on different elements on the page, for example the admin bar, the contact form etc, the popup opens, event though not ordered to do so.
Has anyone had the same issue with elementor popup?
Has it something to do with the jQuery document value? Or should I seek help from elementor?
Got the fix. It is an Elementor bug.. They still have not fixed it, even with the latest update. The issue was not with jQuery code, but with Elementor settings.
I had to eliminate all the popup conditions and triggers from elementor side and just use a dynamic elementor button opening and jQuery button closing.
Somehow the triggers produced the bug, that opened the popup on a random page click.
I have a wordpress site and i used a template to do it. So when i'm on mobile it has a mobile menu i managed to make it fixed to stay at the top when i scroll down, but the problem is. When i'm on a certain place at the site and i wanna open the menu with the "three line" icon it's opening the menu but takes me to the top of the page as well. And when i wanna close the menu with the X button it takes me to the top of the page as well, so basically the menu is unusable. I know it's a Jquery problem, but i can't find which file contain the codes for it and even how to fix it.
My website is: www.autoberles-szombathely.hu
So i wanna make the open menu button and close menu button to only open and close the menu and don't take me to the top of the page.
you can use:
$(selector).click(function(event) {
event.preventDefault();
//other stuff you might want to do on event
});
For the record you should not remove the href entirely, it should always exist to prevent unexpected behavior. If you don't want the href to be be acted on then just use that preventDefault() method, easy and keeps everything running smoothly.
Your menu has the following structure in a mobile viewport:
<i class="fa fa-bars"></i>
The # will cause the page to jump to the top, see here for a detailed answer why.
You have two possibilies to prevent this behavoir:
Add an event handler to this link and use event.preventDefault()
For jQuery
$('.menu-toggle').on('click', function(event){
event.preventDefault();
});
VanillaJs
document.getElementsByClassname('menu-toggle').addEventListener('click', function(event){
event.preventDefault()
});
Remove the attribute href completly (See here). When using this solution you have to use a css-reset or add e.g. cursor:pointer to these links again, because the standard browser css is not applied anymore.
The issue I'm having is that when a modal is opened, the background body is scrollable using the mouse wheel.
Seems like this problem is known and people have suggested to set the body to overflow:hidden as stated in this link:
Prevent BODY from scrolling when a modal is opened
which works fine if your page is short and the modal link is on the initial visible page. However, if you have a longer page and you have to scroll down to see the modal link, once you click to open the modal, the background body shifts to the top.
The background does not scroll anymore, which is what I want, but is there any way to prevent it from popping back to the top when the modal is opened? It's inconvenient when you need to add multiple entries of something using the modal and you have to keep scrolling down to click the modal link to add another item.
In your onclick(I'm guessing you use onclick) event-method insert a return false; at the end, that will prevent the site from scrolling to the top.
I was having a similar problem in which modals larger than the window were cut off, and scrolling anywhere would scroll the background and not the modal.
This question pointed me to this plugin which is simple to use and fully addresses mine in addition to your problem of not permitting the background to scroll:
However this issue is said to be resolved in Bootstrap 3 and the plugin should not be needed if you're using the current version of Bootstrap.
I desire to display a popup. When that popup appears, it has to blur and invalidate the background. The popup contains my content, and it is closed when the user clicks the close button. I choose, squeezbox. but I don't know how to implement it. Please help me with running sample code of squeezebox. I already implemented one set of code, but it's not working.
Do you mean a modal? Something like Bootstrap's Modal?