Is there a way to stop CSS from randomly changing rotation direction after numerous rotations in Safari?

I was tasked with creating a card element that consistently flips in the same direction when clicked. The code snippet I found achieved this perfectly, but only worked on Chrome and Firefox. However, when testing it on Safari on both iOS and MacOS, I encountered a strange issue. After about 20 clicks, the card started flipping randomly back and forth, becoming unpredictable as seen in the screen recording provided.

Is this a common problem and is there a way to prevent this from happening?

let rot = 0;
function flip() {
    rot++;
    const flipContent = document.getElementById("flip").querySelector(".flip-content");
    flipContent.style.transform = `rotateX(${rot * 0.5}turn)`;
    flipContent.style.boxShadow = (rot % 2 === 0) ? `20px 20px 10px 0 rgba(0,0,0,0.4)` : `20px -20px 10px 0 rgba(0,0,0,0.4)`;
}
html, body {
    display: flex;
    margin: 0;
    height: 100%;
    width: 100%;
}
.flip-card {
    width: 70vmin;
    height: 70vmin;
    margin: auto;
    background: transparent;
    perspective: 1000px;
    transition: scale 0.3s;
    scale: 90%;
    cursor: pointer;
}
.flip-content {
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: all 0.6s ease-in-out;
    box-shadow: 20px 20px 10px 0 rgba(0,0,0,0.4);
}
.front-face, .back-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
}
.front-face {
    background-color: blue;
}
.back-face {
    background-color: red;
    transform: rotateX(180deg);
}
.flip-card:hover {
    scale: 100%;
}
<body>
<div id="flip" class="flip-card" onclick="flip()">
    <div class="flip-content">
        <div class="front-face"></div>
        <div class="back-face"></div>
    </div>
</div>
</body>
Here is a screen recording showing the issue on Safari for MacOS

Answer №1

To ensure compatibility with Safari, include the prefix vendor -webkit- in front of the backface-visibility property:

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

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

Fill in the text box based on the selected option from the dropdown menu

My HTML code snippet is as follows: <select name="plot_no" id="plot_no" class="dropdown validate_B"> <option value="">Select number of Plots to book</option> <option value="1">1</option> <opti ...

Ensure that the interface limits the key value to match precisely the value of a constant in Typescript

Seeking assistance in understanding how to enforce a specific type for an optional key within an interface: const FIRST = "FIRST" const SECOND = "SECOND" interface TSomeInterface { element: Element order?: typeof FIRST | typeof ...

Barba.js (Pjax.js) and the power of replacing the <head> tag

I have been using barba.js to smoothly transition between pages without having to reload the entire site. If you want to see an example, take a look here. Here is a snippet of code from the example: document.addEventListener("DOMContentLoaded", func ...

Is the HTML5 capture attribute compatible with wkwebview?

Is it supported as stated in the title? For more information, you can check out the MDN documentation (Incomplete) and the Caniuse list of supported browsers. Surprisingly, none of them mention wkwebview. Does this attribute have support in wkwebview? Kno ...

Struggling to bring an md-button to the front within md-tabs

I'm attempting to insert an md-button into a md-tabs section. Through the use of developer tools, I can confirm that the button is present, but it's not visible: Check out the screenshot here. I tried adjusting the z-index in the CSS to a high ...

To implement the replacement of text with a selected item in AngularJS, simply

I have a dropdown in my HTML: <div class="dropdown"> <button class="dropdown-toggle" type="button" data-toggle="dropdown" ng-model="yearName">Filter by year <span class="caret"></span></button> < ...

JavaScript: handle null values along nested object keys by providing a default value

I am dealing with a complex JSON structure that requires pulling out specific information like this let result = data["a"]["b"][0]["c"]["d"][0]["e"][0] What is a streamlined approach to extract the data? A ...

Text cannot be highlighted within DIV element

Check out this page and this page on my website. Text within the advert DIV tag cannot be selected, and some text in the Incinerator product page is unselectable in the topic-div above the iframe element containing a YouTube video. Here is the relevant HT ...

Fulfill a promise based on a particular event in Puppeteer

I am looking for a way to seamlessly continue my puppeteer code after a particular event occurs. Specifically, I need guidance on how to handle the 'request' event in a synchronous manner. Here is an example of the event code: await page.on(&apo ...

Error in Chart.jsx: Unable to retrieve the length property of an undefined object in the COVID-19 Tracker App

INQUIRY Greetings, I am in need of assistance to identify an error that is perplexing me. The source of this code can be traced back to a tutorial on creating a covid tracker available on YouTube. While attempting to implement the chart feature, I encounte ...

Utilizing Font Awesome icons dynamically presents challenges when integrating with SVG & JavaScript

Recently, I started using the new JS&SVG implementation of font-awesome's v5 icons. It seems to be working perfectly for icons (such as <i class='fas fa-home'></i>) that are already present in the DOM at page load. The <i& ...

What is the best way to uninstall yarn from angular cli so that I can switch to using npm for installing packages?

When attempting to install packages using yarn for tooling, an error occurred stating: 'yarn' is not recognized as an internal or external command, operable program or batch file. Package installation failed with the details provided above. For f ...

Steps for selecting a menubar option on a website?

I'm trying to automate clicking a menu on a website using VBA. Sub SearchBot() Dim ie As Object Dim HTMLDoc As MSHTML.HTMLDocument Dim ckt_No As String ckt_No = Range("A2").Value Set ie = CreateObject("InternetE ...

The offspring selector and the after pseudo-element

So, I have this CSS snippet here: .nav-item > .nav-link:not(.active)::after { content: "test"; display: block; width: 0; border-bottom: solid 2px #019fb6; transition: width .3s; } But now, I want to try something different: .nav-ite ...

AngularJS Implementation for a Dynamic User Interface

After working with MS MVC and KendoUI controls for my web apps, I am now transitioning to a project that will utilize MS WebApi 2.0 for a restful pattern and a Responsive UI consisting of HTML5, Bootstrap, and AngularJS. While I have experience in writing ...

Flame-inspired CSS editor

My current CSS editing workflow goes something like this: I ask for feedback on a page Suggestions are given to make post titles bigger I use Firebug to inspect the post title element I locate the corresponding CSS statement in Firebug (like h2.post_title ...

Default page featuring an AngularJS modal dialog displayed

I am attempting to display a modal popup dialog using an HTML template. However, instead of appearing as a popup dialog, the HTML code is being inserted into the default HTML page. I have included the controller used below. app.controller('sortFiles&a ...

What is the purpose of deserializing the user for every request using PassportJS?

While I have scoured the official documentation and various online resources, I am still unable to find a solution to what seems like an obvious question. When working with Passport.js, it is necessary to define two methods - one for serializing and one f ...

Getting the start of a day for a specific date in JavaScript while considering the timezone

I'm having trouble determining the start of a day while factoring in timezones using javascript. Consider this example: var raw_time = new Date(this.created_at); var offset_time = new Date(raw_hour.getTime() + time_zone_offset_in_ms); // Th ...

Height of border not being displayed accurately

I have been searching for a solution to my unique issue with inserting borders in HTML and CSS. When I try to add a border to three images, the height does not display correctly. This is all part of my learning process to improve my skills in coding. Belo ...