The combination of the card hover effect and the bootstrap modal creates complications

Hey there! I'm in the midst of crafting a webpage using Bootstrap and EJS. My aim is to craft a modal window that pops up when a specific button is clicked to display extra information, and upon clicking an X or "close" button, the modal should disappear. However, the transform effect within the card:hover CSS style seems to be causing issues with the modal window. Here's a snippet of the code to give you an idea:

<%- include('_header'); -%> << header includes Bootstrap css, js and Font Awesome css.
<style>
  /* Card Style */
  .card {
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
  }
  .card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
  }
  .card-header {
    background-color: #007bff;
    color: white;
    border-top-left-radius: 15px;
    border-top-right-radius: 15px;
  }
  // Other styles...
</style>

// Other HTML code...

If you click on the button below, a modal window should pop up in the center of the screen.

                <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#consumerModal<%= consumer.id %>">
                  <i class="fas fa-info-circle"></i>
                </button>

I encountered some unexpected results as seen here:

It appears that the modal window flickers hastily making it hard to interact with. The suggested solution was to momentarily disable the transform using the following JS script:

<script>
  document.addEventListener('DOMContentLoaded', function () {
    var cards = document.querySelectorAll('.card');
    var modals = document.querySelectorAll('.modal');

    modals.forEach(function(modal) {
      modal.addEventListener('show.bs.modal', function () {
        cards.forEach(function(card) {
          card.style.transform = 'none';
        });
      });
      
      modal.addEventListener('hidden.bs.modal', function () {
        cards.forEach(function(card) {
          card.style.transform = '';
        });
      });
    });
  });
</script>

While this resolved the flickering issue, a new problem surfaced where the modal would briefly appear inside the div area before disappearing.

Eliminating the line transform: translateY(-5px); works fine without these complications.

To avoid these complexities, I'm willing to sacrifice the hover effect on the card moving slightly. However, the current situation doesn't seem logical to me, and I'm eager to understand why this is happening so I can proceed smoothly. Any insights into why this might be occurring?

Tried adding JavaScript, tinkered with CSS properties.

Answer №1

function functionToOpenModal(param1, param2){

 var x = document.getElementById("ModalTOShow");
 var body = document.getElementById("ModalBody");
  if (x.style.display === "none") {
    x.style.display = "block";
    body.innerHTML = param1 ;
  } else {
    x.style.display = "none";
  }

}
<style>
  /* Styling for Cards */
  .card {
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
  }
  .card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
  }
  /* Additional Styles for Modal */
  .modal-header {
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: space-between;
  }
  .modal-body {
    padding: 2rem;
  }
  .modal-footer {
    border-top: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    justify-content: flex-end;
  }
  
</style>
<div class="modal fade" id="ModalTOShow" tabindex="-1" aria-labelledby="" aria-hidden="true" style ="display:none">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <h5 class="modal-title" id="consumerModalLabelId">Modal Title</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close">Close Button</button>
                      </div>
                      <div class="modal-body" id="ModalBody">
                       
                          <p id="para"><strong id="strong"></strong> </p>
                        
                      </div>
                      <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Other functinal Button of modal</button>
                      </div>
                    </div>
                  </div>
                </div>
                
        //forEach start()
       <button type="button" class="btn btn-link" data-bs-toggle="modal" onClick="functionToOpenModal('customer Name:jinga','c attribute: lolopipo')">Button to open modal</button>
        // this will render number of fuction calls with different params and those params will be visible/set in modal.
        //forEach end()

Your forEach loop renders the button to open the modal and multiple modals based on the number of customers. It might be better to keep the modal outside the loop and show/hide it using a JavaScript function. You can pass values into the function and use them in the modal.


function functionToOpenModal(param1, param2, ....otherParams){

 var x = document.getElementById("ModalTOShow");
 var body = document.getElementById("ModalBody");
 [retrieve elements by their IDs where you want to place the values]
  if (x.style.display === "none") {
    x.style.display = "block";
    body.value = param1 or param2 or otherParams....
  } else {
    x.style.display = "none";
    body.style.display = "none";
  }

}

            <div class="modal fade" id="ModalTOShow" tabindex="-1" aria-labelledby="consumerModalLabel<%= consumer.id %>" aria-hidden="true">
              <div class="modal-dialog">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="consumerModalLabel<%= consumer.id %>"><%= consumer.name %>'s Details</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                  </div>
                  <div class="modal-body" id="ModalBody">
                    <% Object.entries(consumer.custom_attributes).forEach(([attrKey, attrValue]) => { %>
                      <p><strong><%= attrKey %>:</strong> <%= attrValue.content %></p>
                    <% }); %>
                  </div>
                  <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                  </div>
                </div>
              </div>
            </div>
            <!-- End of Modal -->
<% project.consumers.forEach(consumer => { %>
              <li class="list-group-item bg-light">
                <i class="fas fa-user-tie me-2"></i>
                <%= consumer.name %>
                <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#consumerModal<%= consumer.id %> onClick=functionToOpenModal(<%customer.id%>,<%customer.otherInfo%>,...so on)">
                  <i class="fas fa-info-circle"></i>
                </button>
                </li>
                <%}%>

                
                
                

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

React Material-UI eliminates the 'content' property from the CSS pseudo-element

Creating a React MUI Box and styling it like this: <Box id='my-box' sx={{ '&::before': { content: 'Yay! ', backgroundColor: 'red' } }} >Life is beautiful</Box> However, duri ...

Is there a way to retrieve the value from an input box?

<td class="stockQuantity"> <input class="form-control" id="Cart1" name="qty_req" required="required" type="text" value=""><br> <button type="button" o ...

Iterate over a JSON document, insert an item, and then store the updated data in a separate

My JSON file contains elements like this: var data=[{ "Name": "Jeff", "Age": 35 }, { "Name": "cliff", "Age": 56 }] I need to include a new field called 'Country'. So the updated structure should be: var data=[{ "Name": "Jef ...

Guide to creating a dynamic amount of slides in a React carousel for optimal responsiveness

Looking for a solution to adjust the number of elements displayed in my React Carousel based on available size? I have a React Carousel that currently shows 3 elements at one time. Here is the code snippet: const RCarousel = ({items}) => { const numIt ...

Invalid Data Pusher for User Information in Next JS

Hello everyone, I've been practicing using Pusher with Next.js but encountered an issue where it's showing Error: Invalid user data: 'presence-channel' and I can't seem to solve it no matter how hard I try. Could someone please he ...

Remove the div of the previous selection in jQuery and add the current selection by appending it, ensuring only one selection per row is allowed when

Here is a code snippet that includes buttons appending selections to the "cart" div upon clicking. The first script ensures only one selection per row when multiple buttons in the same row are clicked. In the second script, selections are appended to the ...

Turn off automatic downloading of embedded frame content in Safari for iOS

I am encountering an issue with a modal that displays a PDF and offers two options - one to print and one to download. The download option uses a blob with content-type: application/octet-stream, while the print option utilizes a blob with content-type: a ...

Is it possible to eliminate the sticky class as you scroll down?

Check out this jQuery code I wrote to remove the sticky class while scrolling down: $(window).scroll(function (e) { if ($('.main_form_wrapper').length != 0) { var window_scroll = $(window).scrollTop(); console.log(window_scro ...

Clear the cache in Angular to remove the page

Within my current project, I am utilizing angular's $routeProvider to dynamically load pages into an ng-view section. The loaded pages are displaying correctly in the ng-view and are being cached for quick access without needing to make a new server r ...

Guidance on uploading a file with AJAX in PHP following the display of a Sweet Alert

I am currently facing an issue with inserting a file input (images) into my database. When I try to insert it, the value returned is empty. Below is the script I am using: <script> $("#insertform").on('submit',(function(e) { ...

JavaScript Algorithm for Pyramids

Experimenting with simple algorithms brought me to this code. I'm curious if anyone has a more concise version in JavaScript for displaying a pyramid: const max= 30; let row = 1; for (let i = 1; i < max; i += 2) { console.log(' '.r ...

Tips for triggering jquery code when a variable containing a CSS attribute is modified

I have a specific requirement where I need to reset the scrollleft value to 0 on my wrapper whenever a particular CSS property changes. Although I am new to using jQuery and haven't worked with variables much, I believe I need to create a variable to ...

Ways to modify the values of a Bootstrap Dropdown using a unique identifier

Here is an example of a typical Bootstrap Dropdown: <div class="btn-group"> <button type="button" class="btn btn-lg btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Default option<span class ...

Display a pop-up window upon clicking anywhere on the webpage using jQuery and HTML

Is it possible for me to create a pop-up window that opens a specific website when a user clicks anywhere on the page, similar to pop-up companies? Can this be achieved using HTML, JavaScript, and jQuery? Any help would be greatly appreciated. ...

Leverage nan for the transmission and retrieval of Float32Array within an addon module

I am currently attempting to utilize nan in order to perform calculations on an array of floating point numbers within an add-on and then return the result as a Float32Array. However, while the arguments have IsNumber() and NumberValue() functions, there ...

Using React to iterate over an array of objects and generate Date TextFields in Material UI

I have an array of objects representing different stages in a specific process, each stage identified by an id and name. The structure of the array is as follows: const stages = [ { id: 1, name: initialize }, { id: 2, name: execute ...

Django - tallying timer in action

Looking to add a timer that begins when accessing this template: {% block content %} <h3>C-Test</h3> <p>In the text below, some word endings are missing. The gap is about half the length of the word, so you need to fill in the rest ...

Choose the child nodes upon selecting the root node

I am trying to implement a 2-level material-ui treeview where selecting the root node should automatically select all child nodes as well. Does anyone have suggestions on how to achieve this with material-ui treeview? For more information, please visit ma ...

What is the significance of using composability over the deprecated method in Reactjs Material-UI menuItems?

I have taken over a project that was built using an older version of react, and I am currently in the process of updating it. However, I encountered console errors right off the bat. Error : bundle.js:6263 Warning: The "menuItems" property of the "Left ...

What is the process for modifying the design of an NPM package?

I may have a silly or incorrect question, but what exactly is the extent of default styling in an NPM package? If I am using an NPM package and wish to adjust the color of one of their elements, how should I go about it? In both my own index.css file and ...