The flip animation seems to only display half of the rendering process while anim

Currently, I am working on a div element that has a hover effect to flip and reveal content on the other side. The functionality is mostly there, but I have encountered a frustrating issue that I can't seem to resolve.

During the flip animation, only half of the content that should be displayed on the flipped side is visible. This discrepancy is puzzling me, and I want to address it as soon as possible.

$(function() {
  var frontHeight = $('.front .inner').height();
  var backHeight = $('.back .inner').height();
  var noImg = false;

  if ($('.front-image')) {
    noImg = true;
    $('.flipper').height(backHeight);
  }

  if (frontHeight > backHeight && !noImg) {
    $('.flipper').height(frontHeight);
  } else {
    $('.flipper').height(backHeight);
  }
})
/* container for entire content, maintaining perspective */

.flip-container {
  perspective: 1000px;
  transform-style: preserve-3d;
  position: relative;
  width: 100%;
  height: 100%;
}


/*  UPDATE! Hover effect to flip the pane */

.flip-container:hover .back {
  transform: rotateY(0deg);
}

.flip-container:hover .front,
.flip-container:hover .front-image {
  transform: rotateY(180deg);
}

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

.front .inner h3,
.back .inner h3 {
  color: white;
}

.front-image,
.front-image .inner {
  height: 100%;
  width: 100%;
}


/* defining the speed of flip transition here */

.flipper {
  transition: 0.6s;
  transform-style: preserve-3d;
  width: 100%;
  height: 100%;
  padding: 10px;
  background-color: #3498db;
  color: white;
  position: relative;
}


/* hiding the back of the pane during the transition */

.front,
.back,
.front-image {
  backface-visibility: hidden;
  transition: 0.6s;
  transform-style: preserve-3d;
  position: absolute;
  top: 0;
  left: 0;
}


/*  UPDATE! Front pane rendered above the back */

.front,
.front-image {
  z-index: 2;
  transform: rotateY(0deg);
}


/* initially hidden back pane*/

.back {
  transform: rotateY(-180deg);
}


/*
Updates for vertical flipping
*/

.vertical.flip-container {
  position: relative;
}

.vertical .back {
  transform: rotateX(180deg);
}

.vertical.flip-container:hover .back {
  transform: rotateX(0deg);
}

.vertical.flip-container:hover .front {
  transform: rotateX(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
  <div class="flipper">
    <div class="front">
      <div class="inner">
        <h3>
          cool
        </h3>
      </div>
    </div>
    <div class="back">
      <div class="inner">
        <h3>
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque tempor tincidunt massa, et commodo lorem tincidunt auctor. Duis eu nisi bibendum, vehicula elit in, congue ex. Aliquam erat volutpat. Donec ac leo eu ante vulputate efficitur. Vivamus
          lobortis blandit elit, sit.....
        </h3>
      </div>
    </div>
  </div>
</div>

Answer №1

The issue with your example not functioning properly is due to the background color set on the .flipper element. To resolve this, simply remove the "background-color" property from .flipper and apply it to both .back and .front elements.

.front, .back, .front-image {
    ...
    background-color: #3498db;
}

For a working demonstration, please refer to the following fiddle: https://jsfiddle.net/ymuovwnb/1/

Answer №2

Modify your flipper section as shown below:

<div class="flipper" style="height: 300px;">

Answer №3

To solve the issue, consider removing the background color from the div element that is causing the flip effect.

$(function() {
var frontHeight = $('.front .inner').height();
var backHeight = $('.back .inner').height();
var noImg = false;

if ($('.front-image')) {
noImg = true;
$('.flipper').height(backHeight);
}

if (frontHeight > backHeight && !noImg) {
$('.flipper').height(frontHeight);
} else {
$('.flipper').height(backHeight);
}
})
/* entire container, keeps perspective */
body{
background-color: #3498db;
}
.flip-container {
perspective: 1000px;
transform-style: preserve-3d;
position: relative;
width: 100%;
height: 100%;
}

/*  UPDATED! flip the pane when hovered */

.flip-container:hover .back {
transform: rotateY(0deg);
}

.flip-container:hover .front,
.flip-container:hover .front-image {
transform: rotateY(180deg);
}

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

.front .inner h3,
.back .inner h3 {
color: white;
}

.front-image,
.front-image .inner {
height: 100%;
width: 100%;
}

/* flip speed goes here */

.flipper {
transition: 0.6s;
transform-style: preserve-3d;
width: 100%;
height: 100%;
padding: 10px;
color: white;
position: relative;
}

/* hide back of pane during swap */

.front,
.back,
.front-image {
backface-visibility: hidden;
transition: 0.6s;
transform-style: preserve-3d;
position: absolute;
top: 0;
left: 0;
}

/*  UPDATED! front pane, placed above back */

.front,
.front-image {
z-index: 2;
transform: rotateY(0deg);
}

/* back, initially hidden pane */

.back {
transform: rotateY(-180deg);
}

/*
Some vertical flip updates
*/

.vertical.flip-container {
position: relative;
}

.vertical .back {
transform: rotateX(180deg);
}

.vertical.flip-container:hover .back {
transform: rotateX(0deg);
}

.vertical.flip-container:hover .front {
transform: rotateX(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="flip-container" ontouchstart="this.classList.toggle('hover');">
<div class="flipper">
<div class="front">
<div class="inner">
<h3>
cool
</h3>
</div>
</div>
<div class="back">
<div class="inner">
<h3>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque tempor tincidunt massa, et commodo lorem tincidunt auctor. Duis eu nisi bibendum, vehicula elit in, congue ex. Aliquam erat volutpat. Donec ac leo eu ante vulputate efficitur. Vivamus
lobortis blandit elit, sit amet iaculis neque cursus nec. Etiam convallis erat ac eros blandit, in pharetra urna tristique. Suspendisse sapien dolor, tincidunt id ante vel, venenatis molestie lectus. Ut mattis interdum sapien, ac ornare erat
maximus et. Fusce vestibulum ultricies eros vel rutrum. Integer et libero sit amet diam tincidunt dapibus eu vitae nunc. Sed ultricies leo quis leo semper, nec maximus leo interdum. Morbi porta tortor eget velit sodales, quis venenatis ante
blandit.
</h3>
</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

Double-click to toggle with jQuery

Here is the code for my toggle menu: $(function () { $('#menu li').click(function () { $('#menu li').removeClass("active"); $(this).toggleClass("active"); }); }) It works perfectly, but there is one issue. When ...

having trouble with displaying the results on the webpage

I am facing an issue while trying to display the data fetched from the database: {"results": ["USA", "Canada"]} {"message":"Could not find any countries."} //else An error was encountered in the console: Uncaught TypeError: Cannot read property 'l ...

jQuery UI dynamically adjusting content layout based on browser size changes

Having an issue with my custom accordion script where resizing the browser causes formatting problems in one of the sections. I want the content to remain intact and to utilize a scrollbar if necessary to view the content. The problem is visible in section ...

Restrict the number of clicks allowed on a button

I am working on a project for my college where I need to restrict the number of times a button can be clicked to only 3 times. I have searched everywhere for code to achieve this and finally found some yesterday. The code is functioning partially as it giv ...

Setting distinct fonts for input placeholder and value: A guide

Can different fonts be set for an input placeholder and value? I have a scenario where the input placeholder is in a right-to-left language while the value is in English. Is it achievable using CSS3? ...

The video playback encountered an issue. Unable to access properties of undefined while attempting to play the video

I am facing an issue with my video gallery where I can't seem to play one video at a time. Instead, I keep getting this error message: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'play'). I suspect it may be ...

Swap an iframe for an image pulled from the iframe's URL using jQuery

My plan is to create a variable by extracting an attribute's value in order to add a new object using that variable as the value of another attribute... In my media search site, I am working with a restricted environment where I cannot fully configur ...

`Eliminate a few bbcodes in the code snippet`

I am currently experiencing an issue with a bbcode parser that converts to HTML. Whenever I try to parse the code, I encounter problems with tags that are not in my approved set by the parser. For instance: The parser only permits [b], [center], and [i] t ...

Verify if a Checkbox has been Selected in ContactForm7

I'm facing an issue with checking if a checkbox has been selected using jQuery. I need it to trigger a function when the checkbox is checked. In my WordPress post, I am only required to use the shortcode with the following ID: [contact-form-7 id="7 ...

Looking to display a doc file in a popup window using PHP?

I have been struggling to open a doc file in a pop-up window, but it keeps automatically downloading to my system. Instead of clicking to download the file, I want it to open in a pop-up window. I am using PHP for this. I have searched for a jQuery plug ...

Is there a way to utilize JavaScript in order to trigger a CSS animation to occur at a designated time during a video

I have a cool animated image element that I want to play at a specific point in time during a video using JavaScript. I'm not sure how to make it happen, but I know the .currentTime property could be the key. My goal is for the animation to only play ...

Avoid losing focus on href="#" (preventing the page from scrolling back up to the top)

Is there a way to prevent an empty href link from causing the page to scroll up when clicked? For example, if I have: <a href="#">Hello world</a> And this "Hello world" link is in the middle of the page. When clicked, the URL would look like ...

Countdown Clock in JavaScript for Automatic Logout

I am currently working on creating a countdown timer in JavaScript that should decrement the value of a field by one every minute (for example, starting at 20 and then changing to 19, 18, 17, and so on). However, I am facing issues with its functionality ...

"Troubleshooting the issue of a null object when sending JSON to a WCF Rest Service

I am new to using REST, WCF, and JSON in my application and I'm having trouble with the 'POST' functionality. While the 'GET' method is working fine, the 'POST' method is giving me issues. After packing up my JSON data u ...

What HTML tag is used to define the maximum length and number of lines for text content?

Seeking advice on how to set the maximum length of a line and the maximum number of lines. Should I use a specific element for this task, or would it be better to implement it in TypeScript? ...

Refresh inventory of items using AJAX

Can someone assist me in finding where I made a mistake? I am trying to update the list of comments using ajax after successfully adding one, but instead, I end up seeing this page.https://i.sstatic.net/X7WZi.png The new comment is added to the database, ...

What could be causing my Intel XDK app to malfunction on Android devices?

I have been learning jQuery and created my project using xdk. However, I am facing an issue where the square is not moving when the button is clicked on Android 4.4 (it works fine on my PC). Can someone please help me with this? Here is my code: http://jsf ...

Express in Node.js throwing error: 'Cannot GET /'

I recently created a contact us form on my website where users can input their email, name, and gender. The entered data is then stored in an output.txt file. Everything was working fine when I initially developed the website. However, today when I tried t ...

CSS - reduce the size of an element rather than the entire page

Looking to create a page with 2 divs where the first div automatically shrinks and adds scrollbars when the browser window height is decreased, while the second div maintains its height. Wondering if this can be achieved using only CSS. <div class="s ...

fa icons moving the elements aside

I'm attempting to design a navigation menu with tabs, but I'm facing an issue where the tabs containing "fa icons" are consuming too much space, causing other elements to be shifted to the right or below (if there were more lines). How can I pre ...