1

I have a flip animation on my website. It works on every browser on PC and Android, but does not work on safari. It will flip and you see a flash of the "back" card and then it goes away and you just get a white square. I think I set the -webkit- like it is supposed to be set but for some reason it just isn't working. Does anyone have any ideas?

HTML:

<div class="card">
    <div class="face front hover">
        <img src="images/pawprints_edit.png" width="300" height="180" alt="sign up for al-van newsletter" id="news-img" class="d-inline-block col-md-12 img-fluid my-5 pt-2" />
        <p id="thanks" class="text-center"></p>
    </div>
    <div class="face back">
        <form name="mailForm" class="mail-form" autocomplete="on" novalidate>
            <div class="form-group mb-0 px-2">
                <label for="name">Name:</label>
                <input type="text" class="form-control form-control-sm" id="name" placeholder="John Doe">
            </div>
            <div class="form-group mb-0 px-2">
                <label for="email">Email Address:</label>
                <input type="text" class="form-control form-control-sm" id="email" placeholder="yourname@domain.com">
            </div>
            <div class="form-group mb-0 px-2">
                <label for="message">Please type your message:</label>
                <textarea class="form-control form-control-sm" id="message" cols="30" rows="4"></textarea>
                <input type="button" id="submit" value="Submit">
                <input type="button" id="cancel" value="Cancel">
                <p id="errorP" class="text-center"></p>
            </div>
        </form>
    </div>
</div>

CSS:

/* form animation */

.scene {
    width: 100%;
    height: 300px!important;
    perspective: 1000px;
    -webkit-perspective: 1000px;
    border: none;
}

.card {
    width: 100%;
    height: 100%;
    position: relative;
    -webkit-transition: -webkit-transform 1s;
    transition: transform 1s;
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
    border: none;
}

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

.front {
    background: #98b98a;;
    -webkit-z-index: -1;
    z-index: -1
}

.front.hover {
    background: #98b98a;
    -webkit-z-index: 2;
    z-index: 2;
}

.back {
    background: #4c87a9;
    -webkit-transform: rotateY(180deg);
    transform: rotateY(180deg);
    -webkit-z-index: 1;
    z-index: 1;
}

.back [type=text]:hover {
    cursor: text!important;
}

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

.hover:hover {
    cursor: pointer;
}

/* End animation */

and JS:

/* flip animation script */

function flip() 
{
    'use strict';
    console.log("Flip is being triggered");
    var card = document.querySelector(".card");
    var face = document.querySelector(".front");
    var name = document.getElementById("name");
    var email = document.getElementById("email");
    var errorP = document.getElementById("errorP");
    if(card.removeEventListener)
        {card.removeEventListener("click", flip, false);}
    else if(card.detachEvent)
        {card.detachEvent("onclick", flip);}
    card.classList.toggle("is-flipped");
    face.classList.toggle("hover");
    name.style.background = "#fff";
    email.style.background = "#fff";
    errorP.style.display = "none";
}

/* Function to flip the card back over when canceled */

function cancelFlip()
{
    'use strict';
    console.log("Cancel has been activated");
    var card = document.querySelector(".card");
    var face = document.querySelector(".front");
    card.classList.toggle("is-flipped");
    face.classList.toggle("hover");
    setTimeout(function(){if(card.addEventListener){card.addEventListener("click",flip,false);}else if(card.attachEvent){card.attachEvent("onclick",flip);}console.log("setTimeout was triggered");}, 500);
}

I am using a Boostrap 3 framework. JS is custom and CSS was taken from an online tutorial. The link to the site is: http://www.al-van.org/jake I'm developing on a windows platform and don't have an iPhone to test so I'm having my step-dad check it on his iPhone when I make changes. So far, nothing has been working.

UPDATE: it seems like the form is there, I'm able to click things and input text, but you cant actually see anything. It appears as a white square and nothing is visible. I moved the backface-visibility from .face to each .front and .back to see if that would make a difference. It seems it did not.

sylphaxiom
  • 121
  • 2
  • 12
  • See this other post on this topic, has to do with using backface-visibility to make mobile safari recognise the flip: https://stackoverflow.com/questions/34834349/css-flip-animation-not-working-in-safari. Don't forget to call your functions, I don't see you doing that in your code? – Nathaniel Flick Jun 30 '18 at 04:05
  • I saw that one which is why I used -webkit-backface-visibility: hidden; but for some reason it still isn't working for some reason. Also I forgot to add to the post the eventListener that calls the function on click, but it does exist in the JS page. – sylphaxiom Jun 30 '18 at 04:42

2 Answers2

2

I found the issue. It seems that the .card class had a default background color which made the entire form white, washing out all of its components when flipped. When I removed this default background color and made it transparent. The issue was resolved.

sylphaxiom
  • 121
  • 2
  • 12
1

add backface visibility to your class - .card.is-flipped, because you are using transform on that too

Jismon Thomas
  • 783
  • 1
  • 6
  • 22
  • If the backface-visibility is on the overall card element, would it that apply to .is-flipped as well? Since that class is being applied to the .card element which already has the backface-visibility. – sylphaxiom Jun 30 '18 at 13:43
  • When I made that change the form was no longer functional or clickable on PC browsers. – sylphaxiom Jun 30 '18 at 14:24
  • 1
    Adding `-webkit-backface-visibility: hidden; backface-visibility: hidden;` to my .card class fixed the problem for me. Thanks! – Kewal Shah Dec 10 '19 at 15:56