The back div is not retained on the second animation when flipping the card

In my card with a unique animation, clicking on the "Edit" button triggers the following actions:

  • It smoothly transitions to the center of the screen.
  • During this movement, it rotates by 180 degrees, revealing a blank green back content.

Once the card reaches the center of the div and completes its rotation, it expands to full screen before redirecting the user. However, I encountered an issue where only after the second animation finishes (while all animations are complete), the back content becomes visible. During the rotate and translate functions, only the front content is displayed flipped instead of showing the back content as intended. Refer to the JSFIDDLE link for further details. The HTML code snippet appears below:

<div class="cards-holder">
    <div class="card bg-light mb-3 item" style="display: none">
        <div class="front face">
        <div class="card-header kid-card-header">
            <div class="kid-card-header-name">
                <label>Child name:&nbsp;</label>
                <label>Kevin </label>
            </div>
            <div class="kid-card-header-delete-button">
                <i class="fa fa-trash-o deleteChild" aria-hidden="true" style="cursor: pointer" idOfChild="23"></i>
            </div>
        </div>
        <div class="card-body">
            <div class="kid-card-content">
                <div class="kid-card-content-image">
                    //some image
                </div>
                <div class="kid-card-content-description">
                    <p class="card-text">
                        <label>Age: </label>
                        <label>2 years</label>
                    </p>
                    <p class="card-text">
                        <label>Gender: </label>
                        <label>Male</label>
                    </p>
                    <p class="card-text">
                        <label>Height: </label>
                        <label>50 cm</label>
                    </p>
                    <p class="card-text">
                        <label>Weight: </label>
                        <label>25 kg</label>
                    </p>
                </div>
                </div>
            </div>
            <div class="card-footer kid-card-footer">
                <button class="btn btn-secondary editChildButton" ChildId="23">Edit</button>
            </div>
        </div>
        <div class="back face">
        </div>
    </div>
</div>

The CSS styling applied to achieve the desired effects can be viewed in the subsequent code block along with relevant JavaScript code snippets:

.card {
    transform-style: preserve-3d;
}

.face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
}

    .face.back {
        display: block;
        transform: rotateY(180deg);
        background-color: #78C2AD;
    }

To address the issues faced during animation execution, certain functions were implemented within the provided JavaScript logic. One such function toggles the z-index based on current status while another facilitates smooth rotation along the Y-axis. Event handling is achieved upon clicking the "Edit" button to initiate the sequence of movements and transformations defined. Upon completion of these animations, redirection to a specified page occurs seamlessly. Refer to the attached JSFIDDLE link for a visual representation. Further enhancements showcase accurate card positioning for better understanding.

Answer №1

If you want to optimize performance, consider replacing your JS animation with a CSS animation.

Check out this example for reference: https://jsfiddle.net/g9wb4rwp/

$('.editChildButton').on('click',  function () {       
    $('.flip-container').addClass('flip');       
});
/* Define entire container and perspective */
.flip-container {
perspective: 1000px;
}

.flip-container.flip .flipper {
    transform: rotateY(180deg);
}

.front, .back {
width: 100%;
height: 480px;
}

/* Specify flip speed */
.flipper {
transition: 0.6s;
transform-style: preserve-3d;
position: relative;
}

/* Hide back of pane during swap */
.front, .back {
backface-visibility: hidden;
position: absolute;
top: 0;
left: 0;
}

/* Front pane, placed above back */
.front {
z-index: 2;
/* For firefox compatibility */
transform: rotateY(0deg);
}

/* Back, initially hidden pane */
.back {
transform: rotateY(180deg);
    background: green;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet"/>
<div class="flip-container">
<div class="flipper">
<div class="front">
<div class="card-header kid-card-header">
        <div class="kid-card-header-name">
          <label>Child name:&nbsp;</label>
          <label>Kevin</label>
        </div>
        <div class="kid-card-header-delete-button">
          <i class="fa fa-trash-o deleteChild" aria-hidden="true" style="cursor: pointer" idOfChild="23"></i>
        </div>
      </div>
      <div class="card-body">
        <div class="kid-card-content">
          <div class="kid-card-content-image">
          </div>
          <div class="kid-card-content-description">
            <p class="card-text">
              <label>Age: </label>
              <label>2 years</label>
            </p>
            <p class="card-text">
              <label>Gender: </label>
              <label>Male</label>
            </p>
            <p class="card-text">
              <label>Height: </label>
              <label>50 cm</label>
            </p>
            <p class="card-text">
              <label>Weight: </label>
              <label>25 kg</label>
            </p>
          </div>
        </div>
      </div>
      <div class="card-footer kid-card-footer">
        <button class="btn btn-secondary editChildButton" ChildId="23">Edit</button>
      </div>
</div>
<div class="back">
Back
</div>
</div>
</div>

Handle the end of CSS animation with:

myselector.one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend',  { 
    // Code to run after the transition finishes  
});

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

Ways to position an image in the middle of a Div

I am currently working with PHP and Smarty, attempting to display a slideshow's images in the center of a specific div, but I am encountering difficulties achieving this. Below you will find the code snippet. Can anyone help me figure out what I migh ...

Ways to prevent this column from taking up vertical space

When in desktop mode, I am facing an issue where the image is creating a gap between the "full name" and "Form Number" columns. Is there a way to adjust it so that the full name column starts right below the form number column? I know I could simply place ...

Tips for preventing JavaScript errors when making cross-domain requests using AJAX

Is there a way to prevent or handle JavaScript errors without causing the script to crash? Error message: No data returned $.ajax({ type : 'GET', dataType : 'jsonp', url : '//cvrapi.dk/api?search=dsfsdfsd&country= ...

Tips on stopping slideToggle from opening and closing when clicked for the first time

When using the slideToggle function, I'm encountering an issue where the content div briefly shows on the first click but then immediately slides closed. Subsequent clicks work as expected and slide open correctly. This is the Jquery script I have be ...

Display a div element for a specified amount of time every certain number of minutes

I am currently utilizing AngularJS, so whether the solution involves AngularJS or pure JS does not make a difference. In the case of using AngularJS, I have a parameter named isShowDiv which will determine the switching between two divs based on the follow ...

Tips for utilizing CSS container queries in conjunction with the Material-UI framework

I'm looking to implement CSS container queries with MUI. In my code, I want to change the background color to red if the parent width is less than 300px. Check out the sandbox const StyledItem = styled("div")(({ theme }) => ({ border: ...

Error: Attempted the use of 'append' method on an object lacking the implementation of FormData interface, with both processData and contentType set to false

Apologies for any English errors. I am attempting to use ajax to submit a form, and here is my JavaScript code: $("#formPublicidad").on('submit', function(event) { event.preventDefault(); var dataForm = new FormData(document.getElementBy ...

The styling of the Material UI autocomplete listbox does not affect its appearance

I am working on an autocomplete feature that groups items by titles. I am trying to adjust the height of the first group to be different from the rest, but I am facing some challenges since there is no unique identifier for the ul component. To work around ...

Error: The function pathRegexp is not defined

While attempting to conduct tests on my project with jest, I encountered an error code that seems unrelated to the actual testing process. It appears to be more of a dependency or Node Express compatibility issue. `● Test suite failed to run TypeError: ...

Does JSON hijacking play a role with IE versions greater than 10 or Chrome versions greater than 30?

OWASP suggests wrapping json response with an object rather than returning a direct array. For instance: [{"id":5}] Is this vulnerability still relevant? Could it be exploited? After testing in Chrome, IE, and FF, I couldn't find a way to 'h ...

Using the <audio> tag in HTML5 on Android devices

Exploring discussions on Android's support for the <audio> tag has been enlightening. Despite attempts on a Nexus One running Android Froyo 2.2, it seems playing audio remains elusive. As indicated by www.html5test.com, while the tag is support ...

Add the CSS code to the <head> section, even though the CSS styles are located within

According to the analysis from Webpagetest.org, it appears that The CSS for http://mypage.com/howitworks is located in the document body: The link node for http://mypage.com/design_header.css should be relocated to the document header. The design_header ...

How can I limit the input of string values from a Node Express request query?

export type TodoRequest = { order?: 'asc' | 'desc' | undefined; } export const parseTodoRequest = (requestData: ParsedQs): TodoRequest => { return { order: requestData.order as 'asc' | 'desc' | u ...

Dropdown list control allowing multiple selections

Need assistance in creating a multiple select dropdown list in asp.net. The requirement is to have other controls populated based on the selection of an item without using any third-party tools. Looking for suggestions on how to achieve this using JQuery ...

How can we include a string in the request body in Node.js using Express?

My reverse proxy is functioning properly: app.post('/geoserver', function (req, res) { apiProxy.web(req, res, {target: serverOne}); }); The request already contains a body like this: https://i.sstatic.net/riRBe.png I want to append a stri ...

Validate account existence in Angular 2 before account creation

I am currently subscribing to the following event list and attempting to implement additional checks before completion. userService.createUser(this.form).subscribe((user)=>{ this.user = user }) Here is the service method in question: createAccount(us ...

Is it possible to efficiently bring in NPM packages with their dependencies intact in Deno?

I stumbled upon a helpful post outlining how to incorporate NPM modules in Deno: How to use npm module in DENO? The catch is, the libraries used in the example have absolutely no dependencies. But what if I want to utilize a dependency like Axios (not th ...

VS Code lacks autocomplete intellisense for Cypress

I am currently using Cypress version 12.17.1 on VS Code within the Windows 10 operating system. My goal is to write Cypress code in Visual Studio Code, but encountered an issue where the cypress commands that start with cy are not appearing as auto-comple ...

Exploring the inner workings of AngularJS SEO in HTML5 mode: Seeking a deeper understanding of this hidden functionality

There are plenty of resources available for incorporating SEO-friendly AngularJS applications, but despite going through them multiple times, I still have some confusion, especially regarding the difference between hashbang and HTML5 mode: In hashbang (# ...

Oops! An uncaught exception error occurred because the primordials were not defined

I used npm to install the package called aws-s3-zipper, but now I am encountering an error. This is the code snippet causing the issue: AWS = require("aws-sdk"); var S3Zipper = require("aws-s3-zipper"); function zipFolderOnS3() { var zipper = new S3 ...