I have created an animation of a book with flipping pages. I have used z-index
to stack the pages and they are all flipping and displaying in the correct order in the browser UI but inspector is showing something different.
In Firefox, if I right click on page 1 and select inspect it goes to the element for page 4, I also put input elements on the page but on page 1 I can't click and type in it. Some pages do work normally, inspector goes to the right element and I can type in the input but as I flip through the pages, some pages will stop working and others will start working.
This only happens in Firefox, it work exactly as expected in Chrome. Is this a Firefox issue or a problem with my code?
EDIT: https://codesandbox.io/s/my-book-jlrmw?file=/src/components/HelloWorld.vue
Template:
<template>
<div class="row">
<div class="col-md-12 mb-3">
<button class="btn btn-primary" @click="nextPage">next page</button>
<button class="btn btn-primary" @click="previousPage">previous page</button>
</div>
<div class="col-md-6">
<div class="book">
<span class="front-cover"></span>
<div class="page" v-for="page in pageNums">
<div class="page-side right">
<div class="page-number next" @click="nextPage">{{page[0]}}</div>
<input />
</div>
<div class="page-side left">
<div class="page-number prev" @click="previousPage">{{page[1]}}</div>
<input />
</div>
</div>
<div class="front-cover">
<div class="face front">
<div class="inner-triangle" @click="openBook"></div>
<div class="title">Book</div>
</div>
<div class="face back"></div>
</div>
</div>
</div>
<div class="col-md-6">
</div>
</div>
</template>
Script:
<script>
export default {
name: 'Book',
components: {
},
data() {
return {
bookOpen: false,
numPages: 7,
pageNums: [],
pageNum: 0,
}
},
created() {
this.addPageNums();
},
mounted() {
this.setPageStackOrder();
},
methods: {
addPageNums() {
const pages = this.numPages * 2;
let page = [];
for(let n = 1; n <= pages; n++) {
page.push(n);
if(page.length === 2) {
this.pageNums.push(page);
page = [];
}
}
this.pageNums = this.pageNums.reverse();
},
setPageStackOrder() {
for(let n = 0; n < this.numPages; n++) {
const page = $(".page").eq(n);
page.css("z-index", n+1);
}
const cover = $(".front-cover").eq(1);
cover.css("z-index", 8);
},
openBook() {
if(this.bookOpen === false) {
this.bookOpen = true;
const cover = $(".front-cover").eq(1);
cover.addClass("turn");
setTimeout( () => {
cover.css("z-index", 0)
}, 2500);
}
},
nextPage() {
if(this.bookOpen === true && this.pageNum < this.numPages) {
this.pageNum++;
const zIndex = this.pageNum;
const page = $(".page").eq(this.numPages - this.pageNum);
page.removeClass("turnBack");
page.addClass("turn");
setTimeout( () => {
page.css("z-index", zIndex);
}, 1000);
}
},
previousPage() {
if(this.bookOpen === true && this.pageNum <= this.numPages) {
const zIndex = (this.numPages - this.pageNum) + 1;
const page = $(".page").eq(this.numPages - this.pageNum);
page.removeClass("turn");
page.addClass("turnBack");
setTimeout( () => {
page.css("z-index", zIndex);
}, 2200);
this.pageNum--;
}
},
},
}
</script>
CSS:
<style scoped>
.book {
position: relative;
display: -ms-flexbox;
display: flex;
-ms-flex-direction: column;
flex-direction: column;
min-width: 0;
perspective: 220rem;
}
.front-cover {
background-color: #36354e;
color: white;
font-weight: bold;
position: absolute;
transform-style: preserve-3d;
transform-origin: 0 100%;
top: 0;
right: 0;
width: 50%;
height: 17.5rem;
padding: 1rem;
border-radius: 0 5px 5px 0;
box-sizing: border-box;
}
.face {
position: absolute;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.face.front {
top: 0;
right: 0;
height: 100%;
width: 100%;
-webkit-transform:rotateY(0deg);
}
.face.back {
top: 0;
right: 0;
padding: 40% 0;
text-align: center;
height: 100%;
width: 100%;
transform: rotateY(-180deg);
}
.front-cover.turn {
animation: bookOpen 3s forwards;
}
@keyframes bookOpen {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(-180deg);
}
}
.title {
padding: 40% 0 0 0;
text-align: center;
font-size: 25px;
color: darkgrey;
}
.inner-triangle {
border-left: 20px solid transparent;
border-right: 20px solid green;
border-bottom: 20px solid transparent;
height: 0;
width: 0;
position: absolute;
right: 0;
z-index: 2;
}
.page {
background-color: #e9e6c4;
color: #777;
position: absolute;
transform-style: preserve-3d;
perspective: 120rem;
transform-origin: 0 100%;
top: 0.25rem;
right: 1%;
width: 49%;
height: 17rem;
box-shadow: inset 3px 0px 20px rgba(0, 0, 0, 0.2),
0px 0px 15px rgba(0, 0, 0, 0.1);
}
.page-side {
position: absolute;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
}
.page-side.right {
top: 0;
right: 0;
height: 100%;
width: 100%;
-webkit-transform:rotateY(0deg);
transform: rotateY(0deg);
}
.page-side.left {
top: 0;
right: 0;
height: 100%;
width: 100%;
-webkit-transform:rotateY(-180deg);
transform: rotateY(-180deg);
}
.page.turn {
animation: nextPage 3s forwards;
}
@keyframes nextPage {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(-180deg);
}
}
.page.turnBack {
animation: prevPage 3s backwards;
animation-direction: reverse;
}
@keyframes prevPage {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(-180deg);
}
}
.page-number {
font-size: 0.7rem;
color: #0000FF;
cursor: pointer;
}
.page-number.next {
padding: 5px 10px 0 0;
text-align: right;
}
.page-number.prev {
padding: 5px 0 0 10px;
text-align: left;
}
</style>
You could set all hidden pages to display: none
. If i do that in the firefox dev tools - the issue disappears. Unfortunately i couldn't figure out how to implement this in your program...
Thanks to @biberman for finding that display: none
fixes the issue, I have now found that pointer-events: none
also works, which is better for my purpose.
I have included the changed parts which solve the issue.
I have also reported it as a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1715796
script:
export default {
data() {
return {
pageNum: 1,
}
},
methods: {
openBook() {
if(this.bookOpen === false) {
this.setPageStackOrder();
this.bookOpen = true;
const cover = $(".front-cover").eq(1);
cover.addClass("turn");
setTimeout( () => {
cover.css("z-index", 0)
}, 2500);
const page = $(".page").eq(this.numPages - this.pageNum);
page.removeClass("disable");
page.addClass("enable");
}
},
setPageStackOrder() {
for(let n = 0; n < this.numPages; n++) {
const page = $(".page").eq(n);
page.css("z-index", n+1);
page.addClass("disable")
}
const cover = $(".front-cover").eq(1);
cover.css("z-index", 8);
},
SetPageEvents(direction) {
const cur = this.numPages - this.pageNum;
const next = (direction === "forward") ? cur - 1 : cur + 1;
const prev = (direction === "forward") ? cur + 1 : cur - 1;
const page = $(".page").eq(cur);
const nextPage = $(".page").eq(next);
const prevPage = $(".page").eq(prev);
page.addClass("enable");
page.removeClass("disable");
nextPage.addClass("enable");
nextPage.removeClass("disable");
prevPage.addClass("disable");
prevPage.removeClass("enable");
},
nextPage() {
if(this.bookOpen === true && this.pageNum <= this.numPages) {
const page = $(".page").eq(this.numPages - this.pageNum);
const zIndex = this.pageNum;
this.SetPageEvents("forward");
page.removeClass("turnBack");
page.addClass("turn");
setTimeout( () => {
page.css("z-index", zIndex);
}, 1000);
this.pageNum++;
}
},
previousPage() {
if(this.bookOpen === true && this.pageNum > 0) {
this.pageNum--;
const page = $(".page").eq(this.numPages - this.pageNum);
const zIndex = (this.numPages - this.pageNum);
this.SetPageEvents("backward");
page.removeClass("turn");
page.addClass("turnBack");
setTimeout( () => {
page.css("z-index", zIndex);
}, 2200);
}
},
},
CSS:
.page.enable {
pointer-events: all;
}
.page.disable {
pointer-events: none;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.