CSS Transform flickering on chrome and IE - html

I'm attempting to make a div appear by having it hidden forced via rotate and backface-visibility. The issue is that it is flickering and then disappears after a second. This happens on Chrome. On IE11 it is not appearing at all...
http://jsfiddle.net/1xq96btg/
It's working fine on Firefox.
EDIT: I'm using just backface-visibilty on its own as when I included its variants it became even more unstable and strange behaving.
EDIT 2: z-index doesn't seem to be helping either.
HTML
<div class="one-third-box" onclick="location.href='#'">
<div class="overlay"></div>
<img src="http://www.example.com/image/jpg" />
<div class="box-description">this is a test description</div>
</div>
CSS
.one-third-box {
float: left;
margin-bottom: 2px;
margin-right: 0.2%;
width: 33.2%;
position:relative;
perspective: 1000;
cursor:pointer;
}
.one-third-box:hover {
transform: rotateY(180deg);
transition: 0.6s;
transform-style: preserve-3d;
}
.one-third-box:hover img {
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter:"FlipH";
position:relative;
top:-1px;
}
.one-third-box:hover .overlay {
backface-visibility: hidden;
}
.box-description {
backface-visibility: hidden;
background: none repeat scroll 0 0 #2f5d70;
bottom: 0;
color: #fff;
font-size: 18px;
font-weight: lighter;
height: 38%;
padding-left: 10%;
padding-top: 6%;
position: absolute;
transform: rotateY(-180deg);
width: 100%;
padding-right: 10%;
}
.overlay {
position:absolute;
width:100%;
height:100%;
background:url('images/overlay.png');
}
.one-third-box > img {
width: 100%;
}

I got it to work by changing the CSS a bit...okay, a lot.
I'm assuming that this was being caused by inconsistent hardware acceleration between the overlapping elements and/or that transform-style: preserve-3d; line. Either way, I've created a snippet that seems to work for me. I also chose to go with a CSS animation instead of a transition because it just makes it that much more readable in this case.
* { margin: 0; padding: 0; } /* Simple CSS reset */
.one-third-box {
position: relative;
display: inline-block;
cursor: pointer;
width: 33.2%;
}
.one-third-box > img {
transform-style: flat;
width: 100%;
transform: translate3d(0,0,0); /* Fixes blur from scaling */
}
.box-description {
position: absolute;
box-sizing: border-box;
backface-visibility: hidden;
background: none repeat scroll 0 0 #2f5d70;
bottom: 0;
color: #fff;
font-size: 18px;
font-weight: lighter;
height: 38%;
padding-left: 10%;
padding-top: 6%;
width: 100%;
padding-right: 10%;
transform: rotateY(-180deg);
}
/* ---------------------- Hover effects ---------------------- */
.one-third-box:hover > img,
.one-third-box:hover > .box-description {
-webkit-animation: flip 0.6s;
animation: flip 0.6s;
transform: rotateY(0deg);
}
/* flip animation */
#-webkit-keyframes flip {
from { transform: rotateY(180deg); }
to { transform: rotateY(0deg); }
}
#keyframes flip {
from { transform: rotateY(180deg); }
to { transform: rotateY(0deg); }
}
<div class="one-third-box" onclick="location.href='#'">
<div class="overlay"></div>
<img src="http://www.surgemedia.ie/portfolio-images/alci-clear.png" />
<div class="box-description">this is a test description</div>
</div>

Related

Applying a CSS animation from input:checked that transition works the same way checked and unchecked

I'm trying to do some animation in a div with css rotate() but apparently it only works when I check the label, when I check again just show standard display.
Will be a bonus if someone help me to position the div that I use #rotator before, after vertical, this way they show 45ยบ to a div.
Example: https://codepen.io/rafaart/pen/dyNjgeb
.ativar-dark{
width: 50px;
height: 50px;
display: none;
}
#sky {
background-color: black;
position: absolute;
overflow: hidden;
}
#rotator {
position: relative;
width: 7rem;
height: 7rem;
transform: rotate(-45);
border-radius: 50%;
border: 2px solid red;
margin: 3rem;
}
label{
cursor: pointer;
}
#rotator:before, #rotator:after {
position: absolute;
content: '';
display: block;
height: 3rem;
width: 3rem;
border-radius: 50%;
animation: inherit;
animation-direction: reverse;
}
#rotator:before {
background-color: yellow;
top: -.25rem;
left: -.25rem;
}
#rotator:after {
background-color: White;
bottom: -.25rem;
right: -.25rem;
}
.ativar-dark:checked ~ .container div{
transform: rotate(180deg);
-o-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
transition: all ease 2s;
}
<input type="checkbox" id="ativar-dark" class="ativar-dark">
<div class="container" id="sky">
<label for="ativar-dark">
<div id="rotator">
</div>
</label>
</div>
I have made few tweaks to the code. Kindly check whether it satisfies your requirement.
Your input type contains the id and class of the same name. You mentioned .ativar-dark in the CSS but when I changed it to #ativar-dark it was working fine which is bit strange because id and class can have the same name.
.ativar-dark{
width: 50px;
height: 50px;
display: none;
}
#sky {
background-color: black;
position: absolute;
overflow: hidden;
}
#rotator {
position: relative;
width: 7rem;
height: 7rem;
border-radius: 50%;
border: 2px solid red;
margin: 3rem;
transform: rotate(0deg); /*enter 0 deg in order to return back to the original position when unchecked */
transition: all ease 2s; /* This will make sure it provides the animated effect when unchecked */
}
label{
cursor: pointer;
}
#rotator:before, #rotator:after {
position: absolute;
content: '';
display: block;
height: 3rem;
width: 3rem;
border-radius: 50%;
animation: inherit;
animation-direction: reverse;
}
#rotator:before {
background-color: yellow;
top: 2rem; /* Move the position of circle to center position */
left: -1.25rem;
}
#rotator:after {
background-color: White;
bottom: 2rem; /* Move the position of circle to center position */
right: -1.25rem;
}
#ativar-dark:checked ~ .container div{
transform: rotate(180deg);
-o-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
transition: all ease 2s;
}
<input type="checkbox" id="ativar-dark" class="ativar-dark">
<div class="container" id="sky">
<label for="ativar-dark">
<div id="rotator">
</div>
</label>
</div>
You can toggle two classes using javascript to achieve the rotation on the click of the rotation element. Start with one present in the HTML element, then toggle them on click.
let circle = document.getElementById('rotator')
circle.addEventListener('click', function(e) {
e.target.classList.toggle('rotate')
e.target.classList.toggle('reverse')
})
.ativar-dark {
width: 50px;
height: 50px;
display: none;
}
#sky {
background-color: black;
position: absolute;
overflow: hidden;
}
#rotator {
position: relative;
width: 7rem;
height: 7rem;
transform: rotate(-45);
border-radius: 50%;
border: 2px solid red;
margin: 3rem;
}
label {
cursor: pointer;
}
#rotator:before,
#rotator:after {
position: absolute;
content: '';
display: block;
height: 3rem;
width: 3rem;
border-radius: 50%;
animation: inherit;
animation-direction: reverse;
}
#rotator:before {
background-color: yellow;
top: -.25rem;
left: -.25rem;
}
#rotator:after {
background-color: White;
bottom: -.25rem;
right: -.25rem;
}
.rotate {
transform: rotate(180deg);
-o-transform: rotate(180deg);
-ms-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
transition: all ease 2s;
}
.reverse {
transform: rotate(0deg);
-o-transform: rotate(0deg);
-ms-transform: rotate(0deg);
-webkit-transform: rotate(0deg);
transition: all ease 2s;
}
<input type="checkbox" id="ativar-dark" class="ativar-dark">
<div class="container" id="sky">
<label for="ativar-dark">
<div id="rotator" class="reverse">
</div>
</label>
</div>

backface-visibility doesn't work when used together with an animation

I'm trying to make a card flip effect with CSS keyframes but for some reason the transform: rotateY() doesn't rotate correctly. When it's rotated by the #keyframes, after it passes rotateY(90deg) the front side isn't shown, instead it shows the flipped back side. When flipping the card "manually" (in the inspect element), it works fine.
The card by default is showing the front side. But the animation starts with the back side and then it flips. The animation is keeping its ending state.
As far as I could see, for some reason, the front side is always behind the back side. (If you opacity the back side, the front side can be seen.)
I've tried:
Adding perspective: 1000px; to the parent element
(.cards).
Using positive rotateY() instead of negative.
Adding z-index to .front.
Adding transform: rotateY(0deg); to .front, so it knows that that's the front side.
Adding backface-visibility: hidden; to both, .front and .back.
Adding positon: relative; on one (and both), .front and .back.
But none of these fixed it.
Here you can see a video of the issue:
When #keyframes does it:
https://gyazo.com/7cd4e75c85ed5eba6b1e717a37ce95c2
Manually (When I do it with the Inspect Element):
https://gyazo.com/42e63ff2e4fe0149b917e895a633dd88
Here's the code:
HTML:
<div class="cards">
<div class="card">
<div class="front">
<div class="card-number">5</div>
<img src="https://bounty-assets.fra1.cdn.digitaloceanspaces.com/cards/clubs.png" alt="">
</div>
<div class="back">
<img src="https://bounty-assets.fra1.cdn.digitaloceanspaces.com/cards/back.png" alt="">
</div>
</div>
</div>
CSS:
.cards {
width: fit-content;
display: flex;
position: absolute;
top: 25px;
left: 0;
right: 0;
margin: 0 auto;
perspective: 1000px;
}
.cards .card {
min-width: auto;
width: 208px;
background: transparent;
border: 0;
border-radius: 0;
display: flex;
position: relative;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
margin-left: -30px;
transform: rotateY(0deg);
animation: flipcard 1s linear 0s 1 forwards;
}
.cards .card:first-child {
margin-left: 0;
}
.cards .card .front {
position: absolute;
backface-visibility: hidden;
transform: rotateY(0deg);
}
.cards .card .front .card-number {
position: absolute;
top: 30px;
left: 35px;
font-size: 32px;
font-weight: 600;
}
.cards .card .back {
position: absolute;
transform: rotateY(180deg);
}
#keyframes flipcard {
0% {
opacity: 0;
transform: translate(30vw, 30vh) rotateY(-180deg);
}
30% {
opacity: 1;
transform: translate(0, 0) rotateY(-180deg);
}
50% {
opacity: 1;
transform: translate(0, 0) rotateY(-180deg);
}
60% {
transform: translate(-20px, 0) rotateY(-180deg);
}
80% {
transform: translate(-30px, 0) rotateY(-90deg) scale(1.08);
}
90% {
transform: translate(0, 0) rotateY(0deg) scale(1.08);
}
100% {
transform: translate(0, 0) rotateY(0deg) scale(1);
}
}
I fixed it. Belive it or not, the opacity in the keyframes was causing this issue.

Card Flip animation in HTML CSS not working in IE

This card clip HTML component uses just HTML and CSS, it works except on IE11. On IE11, it is slow and laggy. When I remove backface-visibility:hidden, then it works perfectly on IE11 but I obviously need that line.
What potential fixes are there
https://codepen.io/anon/pen/pKWPVb
<div class="card">
<div class="card__side card__side--front">
</div>
<div class="card__side card__side--back ">
</div>
</div>
CSS
.card {
width: 200px;
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
height: 52rem;
}
.card__side {
border-radius: 3px;
overflow: hidden;
background: #808080;
height: 50rem;
width: 100%;
transition: all 800ms ease;
position: absolute;
top: 0;
left: 0;
backface-visibility: hidden;
}
.card__side--front {
background: red;
z-index: 1;
}
.card__side--back {
transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
}
.card:hover .card__side--front {
transform: rotateY(-180deg);
-ms-transform: rotateY(-180deg);
}
.card:hover .card__side--back {
transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
}
html {
font-size: 5px;
}
Issue in IE is caused with transition.
If using 2 div elements is not necessary to you, I would suggest something like that:
<div class="card">
<div class="card__side card__side--back ">
</div>
</div>
.card {
width: 200px;
perspective: 150rem;
-moz-perspective: 150rem;
position: relative;
height: 52rem;
}
.card__side {
border-radius: 3px;
overflow: hidden;
background: #808080;
height: 50rem;
width: 100%;
transition: all 800ms ease;
position: absolute;
top: 0;
left: 0;
//backface-visibility: hidden;
}
.card__side--back {
transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-webkit-transform: rotateY(180deg);
}
.card:hover .card__side--back {
transform: rotateY(0deg);
background: red;
-ms-transform: rotateY(0deg);
-webkit-transform: rotateY(0deg);
}
html {
font-size: 5px;
}

CSS: 2 sided 3D flip overlapping / bleeding

I am trying to implement a 3D flip effect using two faces in IE (no preserve-3d). See this CodePen for an example: http://codepen.io/djskinner/pen/XbdPpj
The problem is that the two faces overlap at the edges. The issue is present in both Chrome and IE so I assume that there is a problem in the way I have converted this effect to take account for the lack of preserve-3d in IE. Is there a way to prevent this from occurring?
I have achieved the effect without any glitches by utilising the transform-origin property, which then allowed a simple rotation rather than having to perform rotations and translations.
Updated code pen can be found here: http://codepen.io/djskinner/pen/NqNVPx.
Inspiration taken from this code pen: http://codepen.io/jonathan/pen/xiJLn.
Here is an update of your codepen your origin's where updated and I have also added a z-index to your active state so that on hover you cant see the hidden div at the bottom of your 3d box.
hope it helps.
http://codepen.io/anon/pen/pJymRP
$('.cube').hover(function(event) {
$(this).addClass('active');
event.preventDefault();
}, function(event) {
$(this).removeClass('active');
event.preventDefault();
});
$cube-height: 100px;
$negative-half-cube-height: -0.5*$cube-height;
.cube {
border: 1px solid #000;
height: $cube-height;
margin: 0 auto;
position: relative;
width: 60%;
perspective: 1000px;
}
// The two faces of the cube
.default-state,
.active-state {
backface-visibility: visible;
height: $cube-height;
position: absolute;
left: 0;
top: 0;
transition: transform 1.5s ease;
transform-origin: center center $negative-half-cube-height;
-webkit-transform-origin: center center $negative-half-cube-height;
width: 100%;
}
// Position the faces
.default-state {
background-color: #1d92c9;
transform:perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0deg);
}
.active-state {
transform:perspective(1000px) rotateX(90deg) rotateY(0deg) rotateZ(0deg);
}
.active {
.default-state {
transform:perspective(1000px) rotateX(-90deg) rotateY(0) rotateZ(0deg);
}
.active-state {
z-index:99999;
transform:perspective(1000px) rotateX(0deg) rotateY(0deg) rotateZ(0);
}
}
/* Demo styling */
body {
font-family: 'Montserrat', sans-serif;
font-weight: 400;
margin: 70px;
background: #f1f1f1;
}
h1 {
font-size: 20px;
text-align: center;
margin-top: 40px;
}
.cube {
text-align: center;
margin: 0 auto;
}
.default-state, .active-state {
background: #2ecc71;
font-size: 16px;
text-transform: uppercase;
color: #fff;
line-height: $cube-height;
}
.active-state {
background: darken(#2ecc71, 7%);
}
#flipto {
display: block;
text-align: center;
text-decoration: none;
margin-top: 20px;
color: #ccc;
}
<h1>3D FLIP IN IE</h1>
<div class="cube">
<div class="active-state">
<span>...and I flip</span>
</div>
<div class="default-state">
<span>Hover</span>
</div>
</div>

negative effect on opacity transition inside transformed element

Please, try this in action. I change opacity on one element and this affects the look of another static element which contains text. It's hard to explain, just try and tell me how can I avoid this effect. It seems to me that this happens only when using chain of transforms.
http://jsfiddle.net/6p8jf3d3/
HTML:
<div class="outer">
<div class="inner"></div>
<div class="text">Hello</div>
</div>
CSS:
div.outer {
position: absolute;
top: 100px;
left: 50px;
width: 200px;
height: 100px;
border: 1px solid black;
-ms-transform: skew(-45deg);
-webkit-transform: skew(-45deg);
transform: skew(-45deg);
}
div.inner {
width: 100%;
height: 100%;
background-color: #99CCFF;
opacity: 0;
-webkit-transition: all 0.5s;
transition: all 0.5s;
}
div.text {
position: absolute;
top: 0;
left: 0;
font-size: 2em;
font-weight: bold;
-ms-transform: skew(45deg);
-webkit-transform: skew(45deg);
transform: skew(45deg);
}
div.outer:hover div.inner {
opacity: 1;
}
Adding transform: translateZ(0); to div.inner will stop the hopping/jarring effect of the transition, but it keeps the stack fuzz on it. It's better, but not perfect:
Example Fiddle
So, I've experimented a bit (not with this jsfiddle but with larger example) and found solution for Chrome, Safari, Opera and Firefox. Combination of translateZ, backface-visibility and transform-style. jsfiddle.net/6p8jf3d3/4
CSS:
div.outer {
position: absolute;
top: 100px;
left: 50px;
width: 200px;
height: 100px;
border: 1px solid black;
-ms-transform: skew(-45deg);
-webkit-transform: skew(-45deg);
transform: skew(-45deg);
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
div.inner {
width: 100%;
height: 100%;
background-color: #99CCFF;
opacity: 0;
-webkit-transition: all 0.5s;
transition: all 0.5s;
-ms-transform: translateZ(0);
-webkit-transform: translateZ(0);
transform: translateZ(0);
}
div.text {
position: absolute;
top: 0;
left: 0;
font-size: 2em;
font-weight: bold;
-ms-transform: skew(45deg);
-webkit-transform: skew(45deg);
transform: skew(45deg);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
div.outer:hover div.inner {
opacity: 1;
}