I try to have an CSS animated Book in an parallax scroll effect in the header.
Both use CSS 3D transformation. This works fine in Chromium based browsers but not in Firefox.
Removing following transform let the book displayed fine, but also removes the parallax effect.
.container {
/* … */
transform: translateZ(-1px) scale(2);
/* … */
}
The book is based on: https://3dbookcovergenerator.netlify.app/
I haven't found any note that nested translations are not supported, here is actually a sample that works in FireFox.
Would be nice if someone could give me a hint to answer one (or more) of following questions:
- Is it just not supported on Firefox?
- Is just wrong and only works by chance on Chromiums?
- Is there an alternative implementation, that works across browsers (preferable pure CSS and no JS)?
Thanks in advance
A minimal sample:
.book-container {
display: flex;
align-items: center;
justify-content: center;
perspective: 600px;
}
@keyframes initAnimation {
0% {
transform: rotateY(-90deg);
}
100% {
transform: rotateY(-30deg);
}
}
.book {
width: 200px;
height: 300px;
position: relative;
transform-style: preserve-3d;
transform: rotateY(-30deg);
transition: 1s ease;
animation: 1s ease 0s 1 initAnimation;
}
.container:hover .book {
transform: rotateY(-90deg);
}
.book> :first-child {
z-index: 5;
position: absolute;
top: 0;
left: 0;
width: 200px;
height: 300px;
transform: translateZ(25px);
border-radius: 0 2px 2px 0;
box-shadow: 5px 5px 20px #666;
}
.book::after {
z-index: 4;
position: absolute;
content: ' ';
background-color: blue;
left: 0;
top: 3px;
width: 48px;
height: 294px;
transform: translateX(172px) rotateY(90deg);
background: linear-gradient(90deg,
#fff 0%,
#f9f9f9 5%,
#fff 10%,
#f9f9f9 15%,
#fff 20%,
#f9f9f9 25%,
#fff 30%,
#f9f9f9 35%,
#fff 40%,
#f9f9f9 45%,
#fff 50%,
#f9f9f9 55%,
#fff 60%,
#f9f9f9 65%,
#fff 70%,
#f9f9f9 75%,
#fff 80%,
#f9f9f9 85%,
#fff 90%,
#f9f9f9 95%,
#fff 100%);
}
.book::before {
z-index: 3;
position: absolute;
top: 0;
left: 0;
content: ' ';
width: 200px;
height: 300px;
transform: translateZ(-25px);
background-color: #01060f;
border-radius: 0 2px 2px 0;
box-shadow: -10px 0 50px 10px #666;
}
.root {
perspective: 1px;
perspective-origin: center top;
transform-style: preserve-3d;
height: 150vh;
max-height: 100%;
overflow-x: hidden;
}
.container {
padding-top: 20rem;
transform: translateZ(-1px) scale(2);
background-color: #666;
}
.container:hover {
background-color: green;
}
html,
body {
margin: 0;
padding: 0;
height: 100%;
}
.palceholde {
transform: translateZ(0px);
background-color: wheat;
height: 150vh;
}
.book-cover {
background-color: aqua;
height: 100%;
width: 100%;
position: absolute;
padding: 2rem;
box-sizing: border-box;
top: 0;
left: 0;
}
<div class="root">
<div class="container">
<a class="book-container" href="" target="_blank" rel="noreferrer noopener">
<div class="book">
<div class="book-cover">
<h1>Foo</h1>
<strong>BAR</strong>
</div>
</div>
</a>
</div>
<div class="palceholde">
</div>
</div>