Card flip animation using RotateY is experiencing delays in loading

While experimenting with jQuery and CSS3 animations, I encountered a strange issue. When hovering over the card or focusing on the CCV field in my pen, there is a delay in the color transition when the card flips over. It almost seems like it's loading. Any idea what could be causing this? I'm new to jQuery, so please disregard that part unless it's related to the problem.

Find the codepen here: https://codepen.io/maciekmat/pen/MWWVPqX

HTML

<div class="page-container">
  <h1>Fill in your card details</h1>
  <div class="card-scene">
    <div class="card-container">
      <div class="card card-front">
        <div class="card-numbers">
          <p id="cardNumber4">0000</p>
          <p id="cardNumber8">0000</p>
          <p id="cardNumber12">0000</p>
          <p id="cardNumber16">0000</p>
        </div>
        <p id="cardName">M J SMITH</p>
        <div class="sortcode-numbers">
          <p id="cardSortCode1">00</p>
          <p id="cardSortCode2">00</p>
          <p id="cardSortCode3">00</p>
        </div>
      </div>
      <div class="card card-back">
        <div class="black-strip"></div>
        <div class="ccv-strip">
          <p id="cardCcvNum">000</p>
        </div>
      </div>
    </div>
  </div>
  <form action="">
    <label>Account Holder Name</label>
    <input type="text" id="cardNameField" class="card-name" required></input>
    <label>Card Number</label>
    <div class="cardnumber-container">
      <input type="text" id="cardField4" maxlength="4" minlength="4" class="card-number" required></input>
      <input type="text" id="cardField8" maxlength="4" class="card-number" required></input>
      <input type="text" id="cardField12" maxlength="4" class="card-number" required></input>
      <input type="text" id="cardField16" maxlength="4" class="card-number" required></input>
    </div>
    <div class="card-numbers-wrap">
      <div class="sortcodes-wrap">
        <label>Sort Code</label>
        <div class="sortcodes">
          <input type="text" id="sortCodeFirst" maxlength="2" class="sort-code" required></input>
          <input type="text" id="sortCodeSecond" maxlength="2" class="sort-code" required></input>
          <input type="text" id="sortCodeThird" maxlength="2" class="sort-code" required></input>
        </div>
      </div>
      <div class="security-code-wrap">
        <label>Security Code (CCV)</label>
        <input type="text" id="securityCode" maxlength="3" class="security-code" required></input>
      </div>
    </div>
    <button type="submit" id="cardSubmit">Submit</button>
  </form>
  <!--       <a id="cardSubmit">Submit</a> -->
</div> 

CSS:

*{
  box-sizing: border-box;
}

p, a, h1{
  padding: 0;
  margin: 0;
}

body{
  font-family: 'Quicksand', sans-serif;
}

.page-container{
  width: 350px;
  margin: auto;
  display: flex;
  flex-direction: column;
}

.card-scene{
  perspective: 600px;
}

...

jQuery:

$("#cardSubmit").on("click", function (e) {
    e.preventDefault();
    // Logic
});

$(".card-number").keyup(function () {
    // Logic
});

$(".sort-code").keyup(function () {
    // Logic
});

$(".card-container").hover(function () {
    // Logic
});

$('#securityCode').focusin(function () {
    // Logic
});

$('#securityCode').focusout(function () {
    // Logic
});

Answer №1

If you are experiencing the flashing effect when the card flips over and causes a delay, especially in Chrome.

The issue may be related to the absolute positioning of elements on the back of the card, which interferes with the transition until it finishes.

To resolve this, I have eliminated the absolute positioning of black-strip and ccv-strip. As a result, the transition is now much smoother. You may have to use alternative methods to position these elements (Flex should be suitable).

$(".card-container").hover(function() {
  $(this).toggleClass("is-flipped");
});
.page-container {
  width: 350px;
  margin: auto;
  display: flex;
  flex-direction: column;
}

.card-scene {
  perspective: 600px;
}

.card {
  position: absolute;
  margin-top: 1em;
  width: 100%;
  height: 200px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  border-radius: 8px;
  padding: 0 0 26px 40px;
  transition: all .5s ease;
  backface-visibility: hidden;
}

.card-container {
  width: 100%;
  height: 100%;
  transition: transform 1s;
  transform-style: preserve-3d;
  cursor: pointer;
  position: relative;
}

.card-container.is-flipped {
  transform: rotateY(180deg);
}

.card-front {
  background: rgb(228, 228, 228);
  background: linear-gradient(90deg, rgba(228, 228, 228, 1) 0%, rgba(207, 207, 207, 1) 50%, rgba(132, 18, 189, 1) 50%, rgba(20, 106, 162, 1) 100%);
  background-size: 200% 100%;
  background-position: left bottom;
}

.card-back {
  transform: rotateY(180deg);
  background: rgb(228, 228, 228);
  background: linear-gradient(90deg, rgba(228, 228, 228, 1) 0%, rgba(207, 207, 207, 1) 50%, rgba(20, 106, 162, 1) 50%, rgba(132, 18, 189, 1) 100%);
  background-size: 200% 100%;
  background-position: left bottom;
}

.card-numbers {
  display: flex;
  flex-direction: row;
}

.sortcode-numbers {
  display: flex;
  flex-direction: row;
}

.cardnumber-container {
  display: flex;
  justify-content: space-between;
}

.black-strip {
  width: 100%;
  height: 40px;
  background: black;
}

.ccv-strip {
  width: 250px;
  height: 35px;
  background: white;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="page-container">

  <div class="card-scene">
    <div class="card-container">
      <div class="card card-front">

      </div>
      <div class="card card-back">
        <div class="black-strip"></div>
        <div class="ccv-strip">
          <p id="cardCcvNum">000</p>
        </div>
      </div>
    </div>
  </div>

</div>

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

Animation not properly synced with Bootstrap 4 Dropdown hide event

Could you please check out my codepen for clarification: http://codepen.io/anon/pen/oLZOyp Essentially, I have integrated two animations using animate.css into Bootstrap 4 show.bs.dropdown and hide.bs.dropdown events. The animations work on the first show. ...

Show a table containing dynamic information, featuring 10 rows for each column. The header should be present for each additional column that is added

I have incoming dynamic data that I need to display in columns, with 10 records in each row. Currently, I am able to display 10 rows as expected. However, I want the header to repeat each time an additional column is added. How can I achieve this using the ...

The jQuery mouseout functionality seems to be malfunctioning and not responding as expected

I am currently developing a slider that displays details when the mouse hovers over the logo, and hides the details when the mouse moves away from the parent div. jQuery('.st_inner img').mouseover(function() { jQuery(this).parent().siblings( ...

What is the procedure for a parent component to transmit HTML to a child component within Angular?

How can a parent component pass multiple ng-templates to a child component? For example, the parent component includes multiple ng-templates: <app-childcomponent> <ng-template>Item A</ng-template> <ng-template>Item B</n ...

Unusual gaps of white space appearing between React components

Currently developing a small web application with multiple components. The backend functionality is all set, but encountering an unusual styling issue. Specifically, noticing a white space appearing between each component without any clear reason. This ga ...

Is there a way to adjust the theme color in _variables.scss by recompiling Bootstrap while working with Angular and CSS?

I've been trying to update the primary color in my Angular project by editing the SCSS file node_modules/bootstrap/scss/_variables.scss. However, after stopping npm and running the front-end again, I noticed that the changes I made are not reflected i ...

Is there a way to integrate an After Effects animation onto my website?

Being a beginner in the world of coding, I am determined to learn by building my own personal website. However, I have encountered a challenge with after effects. I have designed an animation for the welcome screen of my website using my logo and a welcome ...

Enhancing the background of a website with the power of CSS

I am looking to create a customized table without the balls/pots in it. The number of rows on the y-axis will vary depending on the number of names I have, and can be more or less. The values on the x-axis are determined by a parameter included in the URL ...

Although JQuery is able to remove a row from the page, the record in the database is not

I'm having some trouble using jQuery and Ajax to delete a row on the page as well as a record in the database. The row on the page is successfully removed, but the PHP file isn't being called. I only have an echo statement in the PHP for error ch ...

The .change() function is only executing once and not triggered by multiple clicks

I have a JavaScript file that runs automatically through an HTML script. The issue I am facing is with the putToggleCall() function, which should be triggered every time one of the toggles is clicked. However, it only executes once, even before the docum ...

Extracting Data: Unlocking Information from Websites

My friend and I are working on a school project that involves creating a small application. The main goal of this app is to find pharmacies in our area. I am looking to extract information from two specific websites. gun = day/date lc = id of town ...

Tips for accessing basic information from these websites without encountering CORS issues

Having issues retrieving data from the following two sites: and Eurolottery. The CORS issue is causing the problem, and I was able to retrieve data using a Chrome CORS extension and the provided code below: var HttpClient = function() { this.get = fu ...

I seem to be facing some difficulty in dynamically calling my buttons in AngularJS

Can you assist me in solving this problem? I am new to Angular and just starting out. Initially, there is only one button on load called "Add list". When the user clicks on this button, they are able to add multiple lists. Each list contains a button labe ...

What is the most effective way to set image width using jQuery during the DOM ready event

Hello everyone, I have a question about the jquery data() method and how it is used to store image widths. At what point in the page loading process can jQuery retrieve the width of images? Is it during the DOM ready state or after the images are loaded? ...

What do you do when you need to hide a table column that has a colspan

I have been searching for a solution to my unique table structure, but I haven't found any that match my situation. When attempting to hide column A or B, the following code works perfectly: $('table td:nth-child(1),table th:nth-child(1)') ...

Combining several files into a single variable to encode

I'm encountering an issue with the multiple file upload option. Even though it shows that 2 files have been uploaded, when I try to print the encoded value in the console, it only encodes and takes the value of my last uploaded file. How can I encode ...

How can I prevent the "flashes" that occur on load when setting the width of JQuery/Select2 to 100%?

My HTML page uses JQuery and Select2 to create several <option>s, which works smoothly. However, there is a brief moment (around 0.5-1 second) where it displays mySelectBox and mySelectBox2 separately before reformatting them to width=100%. This ini ...

Steps for breaking down a given string into divisions that correspond to an A4 sheet

Within my content, there are various styles applied. For example: This is a <b>bolded</b> word. I am seeking a solution to divide this long string into smaller sections that would fit on an A4 page accurately. The goal is to maintain the integ ...

using jtemplates to append content rather than replacing it

Currently, I am utilizing jtemplates as my preferred templating solution (a fantastic jQuery plugin). Replacing my asp.net updatepanels with this tool has tremendously boosted the speed of my website. The only snag I've hit is when loading user commen ...

Adjusting the border-right size based on scroll position

Apologies if this question seems trivial, but I am completely new to coding in HTML and JavaScript. I understand that I can make some changes based on scroll position, but right now I'm a little confused. I want to increase the height of a box as the ...