Spin Card Animation Malfunction

I've been working on creating a rotating card animation, but I've run into a glitch that's causing the front side to be visible through the back. This issue seems to occur when using position: absolute elements inside one of the sides. While it's somewhat manageable in Chrome, Safari makes it difficult to get my design working without this bug. Below is some code that's glitching on both browsers, and I'm looking for advice on how to resolve this issue.

var isLeft = true;
var x = document.getElementById("card");

setInterval(function() {

  if (isLeft) {
    x.style.transform = 'rotateY(360deg)';
  }
  else {
    x.style.transform = 'rotateY(0deg)';
  }
  isLeft = !isLeft;
  
},5000);
.scene {
  width:480px;
  height:480px;
  perspective: 35em;
  position: absolute;
  left: 100px;
  top: 100px;
}

.card {
  width:220px;
  height:380px;
  left: 130px;
  top: 50px;
  position:absolute;
  transition: transform 4s;
  transform-style: preserve-3d;
}

.face {
  border-radius: 10px;
  width:100%;
  height:100%;

  color:#FFF;
/*   line-height:15em;
 text-align:center;*/
  position:absolute;

  backface-visibility:hidden;
  -webkit-backface-visibility: hidden;
}

.front {
    position:absolute;
background-color:white;
  /*border: 1px solid black;*/
}

.back {
    position:absolute;
  background-color:white;
  transform: rotateY(180deg);
  overflow: hidden;
  /*border: 1px solid black;*/
}
<div class="scene" id="scene">
  <div class="card" id="card">
    <div class="face front">

      <div style="width: 100%; height: 100%; background-color: purple; position: absolute;"></div>
      <div style="width: 100px; height: 100px; background-color: red; position: absolute;"></div>

      <div style="width: 100px; height: 100px; bottom: 0px; right: 0px; background-color: green; position: absolute;"></div>
      <div style="width: 30px; height: 30px; background-color: blue; position: absolute;"></div>

    </div>
    <div class="face back">

      <div style="width: 100%; height: 100%; position: absolute; color: white;">

    </div>
  </div>
</div>

Answer №1

Consider adding z-index: 1; to the .face class for proper layering:

var isRotated = true;
var obj = document.getElementById("box");

setInterval(function() {

  if (isRotated) {
    obj.style.transform = 'rotateY(360deg)';
  }
  else {
    obj.style.transform = 'rotateY(0deg)';
  }
  isRotated = !isRotated;
  
},5000);
.container {
  width:480px;
  height:480px;
  perspective: 35em;
  position: absolute;
  left: 100px;
  top: 100px;
}

.box {
  width:220px;
  height:380px;
  left: 130px;
  top: 50px;
  position:absolute;
  transition: transform 4s;
  transform-style: preserve-3d;
}

.face {
  border-radius: 10px;
  width:100%;
  height:100%;
  
  color:#FFF;
/*   line-height:15em;
 text-align:center;*/
  position:absolute;
  
  backface-visibility:hidden;
  -webkit-backface-visibility: hidden;

  z-index: 1; /* important for stacking elements */
}

.front {
    position:absolute;
background-color:white;
  /*border: 1px solid black;*/
}

.back {
    position:absolute;
  background-color:white;
  transform: rotateY(180deg);
  overflow: hidden;
  /*border: 1px solid black;*/
}
<div class="container" id="container">
  <div class="box" id="box">
    <div class="face front">

      <div style="width: 100%; height: 100%; background-color: purple; position: absolute;"></div>
      <div style="width: 100px; height: 100px; background-color: red; position: absolute;"></div>

      <div style="width: 100px; height: 100px; bottom: 0px; right: 0px; background-color: green; position: absolute;"></div>
      <div style="width: 30px; height: 30px; background-color: blue; position: absolute;"></div>

    </div>
    <div class="face back">

      <div style="width: 100%; height: 100%; position: absolute; color: white;">

    </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

Dimensions of images on Read the Docs (small image widths)

Using MkDocs along with the Read the Docs theme, I am facing an issue with small images not scaling properly on mobile devices. It seems like this problem is related to the CSS of Read the Docs theme, but I'm unsure how to override the default behavi ...

No Access-Control-Allow-Origin or Parsing Error with jQuery

I am attempting to use ajax from a different server to request data from my own server as a web service. The response is a valid json generated by json_encode. {"reference":"","mobile":"","document":"","appointment":""} To avoid the 'Access Control ...

Targeting lightgallery.js on dynamically added elements in Javascript: The solution to dynamically add elements to

I am facing a challenge in targeting dynamically added elements to make them work with lightgallery.js. Take a look at the example below: <div id="animated-thumbs" class="page-divs-middle"> <!-- STATIC EXAMPLE --> ...

Modify appearance of text depending on input (HTML & JS)

I am currently working on building an HTML table using Django. My goal is to dynamically change the color of numbers in the table to red when they are negative and green when they are positive. I understand that JavaScript is required for this functionalit ...

The columns in the table are hidden when resizing

There are three tables in my code. The first table does not have any margin set, while the next two tables have a margin-left property to slightly move them to the left side. However, when I resize the window, I'm unable to see the last column in the ...

How to Reset Text Fields with a Button Click in Vue.js?

I am currently working on a layout where I need to loop through text fields and buttons. How can I implement a function for each button that clears only the corresponding fields? Take a look at this fiddle here. <div id="app"> <h2>Each text ...

Choose to show a blank option and then retain the selected value upon submission

Is there a way to have the initial selection in a dropdown list be blank and selected by default, but still preserve the selected value after submitting the form? For example: <form action="" method="post" /> <SELECT NAME="whatever" id="whatever ...

Tips for Utilizing Both getElementByID and getElementByTagName Functions in JavaScript

Hi! I'm a beginner in JavaScript and I've managed to retrieve some data using getElementById. Now, I want to extract a specific part using getElementsByTagName. document.getElementById('titleUserReviewsTeaser').innerHTML; " < ...

Can you clarify the functionality of this loop? I am having trouble grasping how it produces the final result

Seeking clarification on the highlighted section] https://i.sstatic.net/dyrKS.png I need assistance in understanding how the use of "text" helps to print the following literal. ...

My jQuery code is encountering issues with the .each loop functionality

I have encountered an issue with the code snippet below, which is intended to hide the "IN STOCK" phrase on specific vendors' product pages. Upon testing, I noticed that the loop doesn't seem to be executing as expected when using console.log. Ca ...

Obtain the URL path for accessing URL links using PHP

To obtain the URL of an image, I typically use this code on the main websites: <a href="./index.html"><img src="./images/logo.png" class="" alt=""></a> However, for sub-sites, I need to use a slightly different approach: <a href=".. ...

Challenge with uploading Minio presigned URLs

I am encountering a problem with the Minio presigned URL. While I have successfully obtained the URL and used the PUT method to insert my file into my Minio bucket, I am unable to open certain file types such as jpg, png, or pdf. This is due to Minio autom ...

Only the initial column can be replaced by the setColumn function

After attempting to remove an item from the column and updating it with a new column, I noticed that setColumns only replaces the first column. Although the data in the column is correct, the placement is incorrect. Here is the initial state: https://i.ss ...

Error encountered: No geographic indices found for executing a geoNear operation with Mongoose

Initially, I had divided the schemas but later nested them inside my overall document. Despite adding indexes and removing coordinates from location, there seems to be an issue with the nested points. Upon running get Indexes, it shows that there is an i ...

The excessive repetition in Angular flex layout is becoming overwhelming

I discovered and started using the responsive API provided by angular flex layout. While most of the time it works as intended, there are instances where I find myself duplicating directives in the code. Here's a simplified example: <div> &l ...

What is the best way to trigger the jQuery-File-Upload event within this function?

Before uploading a file, I want to check the API first. $('.file_upload_button_wrapper').on('click', function () { // perform check here $.ajax({ url: '/?app=files&getfile=ajax%2Fupload.php', ...

Steps for launching a fresh script within the current tab

I'm currently working on a project where I have the following code: window.open("http://localhost/xyz.php") When this code runs, it opens the PHP file in a new tab within the same window. However, I'm trying to figure out how to make it open in ...

Modifying the type of a DOM element based on the value of an AngularJS

My main goal is to dynamically change the type of a DOM element based on a scope variable. Imagine I have a scope variable like this: $scope.post = { title: 'Post title goes here!', slug: 'post-title-goes-here', category: ...

Sending a property as a parameter to a different component through Vue's router-link

I have a component designed to showcase recipes in a list format. Each recipe is rendered using a separate component from an array of recipes. I am currently attempting to pass the recipe object from one component to another component using Router-Link ...

Flipping back and forth between two images within a single HTML file

I am looking to customize my top navbar for two different webpages, the root URL (/) and firstpage (/firstpage). The top navbar contains 2 images that I want to switch based on which page the user is currently on. Here is the code snippet: <img class=" ...