Ask Your Question
1

How to display Modal at the bottom and make the background blurred?

asked 2022-03-21 11:00:00 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-06-06 17:00:00 +0000

djk gravatar image

To display a modal at the bottom and make the background blurred, you can use the following CSS and JavaScript:

CSS:

.modal { position: fixed; bottom: 0; left: 0; width: 100%; height: 100%; z-index: 9999; background-color: rgba(0, 0, 0, 0.6); filter: blur(5px); display: flex; align-items: flex-end; justify-content: center; }

.modal-content { width: 80%; max-width: 600px; margin-bottom: 50px; }

JavaScript:

// Get modal element var modal = document.getElementById('myModal');

// Get close button var closeBtn = document.getElementsByClassName('close')[0];

// Listen for close click closeBtn.addEventListener('click', closeModal);

// Listen for outside click on modal window.addEventListener('click', outsideClick);

// Function to open modal function openModal() { modal.style.display = 'block'; }

// Function to close modal function closeModal() { modal.style.display = 'none'; }

// Function to close modal if outside click function outsideClick(e) { if (e.target == modal) { modal.style.display = 'none'; } }

You can then use the following HTML to create your modal:

Note: This code assumes that you have a button or other element that triggers the modal to open, and that it has an onclick function that calls the openModal() function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-03-21 11:00:00 +0000

Seen: 8 times

Last updated: Jun 06 '21