Card Flip css/js effect does not work in safari

Asked

Viewed 141 times

0

I have a simple code I developed, from a card flip effect, example below.

Works on google quiet, but I found that in safari has a bug when the card turns, I searched on, I found some prefixes for safari but I can not find a solution, missing some prefix support for safari?

The bug in safari is that when the card flips with the click, the background does not appear, just the front.

let card  = document.getElementById("card")

let frente = true

card.addEventListener("click", (event) => {
  if (frente == true) {
    card.style.transform = "rotateY(180deg)"
    frente = false
  }
  else {
    card.style.transform = "rotateY(0deg)"
    frente = true
  }
  event.stopPropagation()
})
body, .content, html {height: 100%}
* {margin: 0; padding: 0; box-sizing: border-box; font-family: sans-serif;}

.content {
  align-items: center;
  background-image: linear-gradient(to top, #dfe9f3 0%, white 100%);
  display: flex;
  justify-content: center;
  perspective: 600;
}

.card {
  background-color: #fff;
  box-shadow: 0px 2px 10px #444;
  height: 480px;
  position: relative;
  transition: all 0.5s ease-in-out;
  transform-style: preserve-3d;
  width: 320px;
}

.card .side {
  backface-visibility: hidden;
  height: 100%;
  position: absolute;
  overflow: hidden;
  cursor: pointer;
}

.card .back {
  background-color: #fff;
  backface-visibility: hidden;
  height: 100%;
  position: relative;
  transform: rotateY(180deg);
  width: 100%;
  z-index: 102;
}
<div class="content">
  <div id="card" class="card">
    <div class="side">
      side
    </div> <!-- .side -->
    <div class="back">
      back
    </div> <!-- .back -->
  </div> <!-- .card -->
</div>

Obs: error happens only in safari.

BS: I have this code in codepen if it helps https://codepen.io/lennon/pen/qMPqGX

  • Which version of safari?

  • @Máttheusspoo 11.2

  • https://www.w3schools.com/jsref/prop_style_transform.asp .style.transform is not supported by safari browser.

  • Because you don’t create an active . type class, and you put the CSS properties you want in it. and then with JS vc just does the class toggle by taking out and putting the CSS in the click, like a jQuery toggleClass

  • @Máttheusspoo that mess of mine, but I did not understand how I would solve with JS?

  • @hugocsl good idea, I’ll test.

  • Try adding another line with the prefix in JS: card.style.webkitTransform = "rotateY(180deg)" and card.style.webkitTransform = "rotateY(0deg)"

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.