我正在尝试使用 jquery 和 css3 创建翻页。如果我将 2 个页面放在 1 个容器中然后旋转整个容器,我可以做到这一点,但我只想旋转我的页面。这是我的代码:
CSS:
#pagecontainer {
position: absolute;
width: 100%;
height: 100%;
}
.page {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
-o-backface-visibility: hidden;
backface-visibility: hidden;
}
.back {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
}
.flip.out {
-webkit-transform: rotateY(180deg);
-moz-transform: rotateY(180deg);
-ms-transform: rotateY(180deg);
-o-transform: rotateY(180deg);
transform: rotateY(180deg);
-webkit-transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
-moz-transform-style: preserve-3d;
-moz-transition: all 1.0s linear;
-o-transform-style: preserve-3d;
-o-transition: all 1.0s linear;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
.flip.in {
-webkit-transform: rotateY(0deg);
-moz-transform: rotateY(0deg);
-ms-transform: rotateY(0deg);
-o-transform: rotateY(0deg);
transform: rotateY(0deg);
-webkit-transform-style: preserve-3d;
-webkit-transition: all 1.0s linear;
-moz-transform-style: preserve-3d;
-moz-transition: all 1.0s linear;
-o-transform-style: preserve-3d;
-o-transition: all 1.0s linear;
transform-style: preserve-3d;
transition: all 1.0s linear;
}
然后,我将这些类添加到页面容器中的页面中:
container.append(nextPage);
nextPage.attr("class", "page back");
currentPage.one('webkitTransitionEnd', function(e) {
currentPage.remove();
});
nextPage.attr("class", "page back flip in");
container[0].offsetWidth;
currentPage.attr("class", "page flip out");
但只有正面在翻转?我究竟做错了什么?
编辑: 解决了。我需要将脚本中的顺序更改为:
currentPage.attr("class", "page flip out"); <-- Start with this
container[0].offsetWidth;
nextPage.attr("class", "page back flip in"); <-- Finish with this