Tips for expanding the width of Bootstrap modal using animation

Is there a way to resize my Bootstrap 5 modal width and add an animation effect when it expands? I've tried using animate and transition in my style-css but haven't had any success so far. I've looked at other solutions online, but none seem to work for me. How can I achieve this? Thank you!

TEMPLATE

<template>
  <div class="modal fade modal-sm" id="modalID" tabindex="-1">
    <div class="modal-dialog" :class="resizeModal == true ? 'size-modal' : ''">
      <div class="modal-body">
        <button class="btn btn-dark col-3" @click="resizeModal = !resizeModal"></button>
      </div>
    </div>
  </div>
</template>

SCRIPT

<script lang="ts" setup>
import { ref } from "vue";
const resizeModal = ref(false);
</script>

STYLE

<style>
.size-modal {
  --bs-modal-width: 80%;
}
</style>

Answer №1

Make sure to adjust the style attribute in order to incorporate a smooth transition for the max-width property on your modal-dialog component.

<style>
.size-modal {
  --bs-modal-width: 80%;
}
#modalID>.modal-dialog {
  transition: max-width .5s ease-in-out;
}
</style>

Answer №2

It would be greatly appreciated if you could provide a concise and reproducible example.

Here are some initial steps you can try:

  • Update your template by incorporating a conditional class into your modal dialog
<template>
  <div class="modal fade" id="modalID" tabindex="-1">
    <div class="modal-dialog" :class="{ 'size-modal': resizeModal }">
      <div class="modal-content">
        <div class="modal-body">
          <button class="btn btn-dark col-3" @click="resizeModal = !resizeModal">
            Toggle Size
          </button>
        </div>
      </div>
    </div>
  </div>
</template>
  • Regarding your script, ensure that resizeModal is a reactive variable in Vue

  • Include CSS for animation and manage the width transition

<style>
.modal-dialog {
  transition: width 0.5s ease-in-out;
}

.size-modal {
  width: 80% !important; /* Customize as necessary */
}
</style>

This approach should be effective in resolving your issue.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: Exceeded the hook limit during rendering - reactjs problem

I keep encountering an issue when trying to retrieve main data using useSwr, where I call another function with axios and end up with an Uncaught Error: Rendered more hooks than during the previous render. I've attempted to troubleshoot this countless ...

Obtain the distinct highest value for every vertical axis on a bar graph

I'm facing an issue with my code where I am appending multiple SVG elements and generating 3 different charts. The problem is that the maximum value evaluated from the y.domain() for each y-axis is taken as the maximum value from all of my data. Is t ...

Is there a way to disregard the active region of a child element while the parent is active?

Currently, I am working on building a to-do list application using React. In the CSS styling, I have implemented an animation for when an li element is active, causing it to expand in height. The issue arises from the fact that I have also set up an onClic ...

Why is the 'a' element not clickable after the AJAX complete function has executed in JavaScript?

I have a small question regarding my use of AJAX. Everything is working fine, but after the AJAX request completes, I am trying to change the element attributes such as backgroundImage dynamically. Although this process works correctly, the element that wa ...

What is the best way to merge two interfaces and convert all of their fields to optional properties?

I have two unalterable interfaces: interface Person { name: string; age: number; } interface User { username: string; password: string; } I aim to merge them into a single interface called Player // please, adjust this code accordingly interfac ...

The term 'EmployeeContext' is being utilized as a namespace in this scenario, although it actually pertains to a type.ts(2702)

<EmployeeContext.Provider> value={addEmployee, DefaultData, sortedEmployees, deleteEmployee, updateEmployee} {props.children}; </EmployeeContext.Provider> I am currently facing an issue mentioned in the title. Could anyone lend a hand? ...

@mui/x-date-pickers styling for the DatePicker component

Despite numerous attempts, I have been unsuccessful in styling the @mui/x-date-pickers <DatePicker/> component. I've experimented with various methods such as sx={{}}, style={{}}, makeStyles(), .css with the !important rule, renderInput={(param ...

Display the hidden element using jQuery with the !important rule

There is a specific element that has been given a class with the following CSS styling: .cls { display:none !important; } Despite attempting to display this element using jQuery $(".cls").show(); This method does not seem to be effective. Is ...

Backend framework

Currently, I am in the process of developing a robust web application that heavily relies on JavaScript and jQuery, with ajax functionality included. Additionally, there will be a database in place, managed using mySQL with several tables. I'm undeci ...

Looking to expand the width of the sub menu to reach the full width of the

Is there a way to use CSS to make a sub-menu start from the left side of the screen instead of starting it below the parent item? nav { margin: 0 auto; text-align: center; } nav ul ul { display: none; } nav ul li:hover > ul { di ...

Unable to designate NODE_ENV as production by utilizing npm and webpack

I'm encountering an issue while trying to access process.env.NODE_ENV within my application. Whenever I check it, I only receive the error message process is not defined. package.json: "scripts": { "dev": "node ./node_mod ...

Reading properties of undefined in React is not possible. The log method only functions on objects

I'm currently facing an issue while developing a weather website using the weatherapi. When I try to access properties deeper than the initial object of location, like the city name, it throws an error saying "cannot read properties of undefined." Int ...

How to ensure the right size for your sections in HTML5

I am currently learning HTML5 and attempting to create a specific sized section in the browser where various elements like buttons and text will be displayed based on user interaction. However, I am running into an issue with adjusting the size of the sect ...

What is the proper way to add a line break within a Custom JSX Tag that is imported from a different class in the code

<Experience startYear={2019} endYear={2019} jobName="First Job" jobDescription="1. Providing API calls support for Headless CMS. 2. Provide escalated ticket/incident management support" ...

Can you please explain the significance of (session?._id)?

export default NextAuth({ ... callbacks: { session: async ({ session, token }) => { if (session?.user) { session.user.id = token.uid; } return session; }, jwt: async ({ user, token }) => { if (user) { ...

What is the process for incorporating Angular.js with a live messaging platform such as Pusher or PubNub?

Can Pusher or PubNub be implemented as an Angular service? Anyone have any examples of code for this kind of integration? ...

"Make sure to tick the checkbox if it's not already selected,

Could use some assistance with traversing and logic in this scenario. Here is the logic breakdown: If any checkbox in column3 is checked, then check the first column checkbox. If none in column 3 are selected, uncheck checkbox in column1. If column1 ...

Error: Unable to locate the reference

Having trouble with my JavaScript code not recognizing the linked .js files I added. I initially linked them through CodePen, but manual references don't seem to be working. Attempted suggestions from this page Why does jQuery or a DOM method such as ...

When using the <a> tag in an ASP.NET MVC view, the hyperlink may be missing

When utilizing ASP.NET MVC 5, I encountered an issue within my view where I am attempting to incorporate "Edit | Delete" functionality within a table. Strangely, I am able to generate a hyperlink for the Edit function, but not for the Delete function. Wit ...

Create a JavaScript button that increases a progress bar value by 1 and adjusts its width style by 10 units

Here is the code for managing a progress bar using JavaScript: function getProgress() { return document.getElementById("progressbar").getAttribute("aria-valuenow"); } function setProgress(value) { document.getElementById("progressbar").setAttri ...