我正在尝试使用CSS3的translateZ()
建立一个滚动“放大”的网站。网站的每个部分都是一个带有“窗口”的面板,当您放大时,您将浏览此窗口并接近下一部分。看看这个片段,我会更清楚我所追求的。
var main = document.getElementsByTagName('main')[0]
document.getElementById('scroll').style.height = window.getComputedStyle(main).height.slice(0, -2) * main.getElementsByTagName('section').length;
var has_scrolled = false;
window.addEventListener('scroll', function() {
has_scrolled = true;
})
var navigate = function() {
window.requestAnimationFrame(navigate);
if (has_scrolled) {
main.style.transform = "translate3d(-50%, 0, " + (window.pageYOffset) + "px)"
has_scrolled = false;
}
};
navigate();
*,
*::before,
*::after {
margin: 0;
padding: 0;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
body {
height: 100%;
width: 100%;
font-size: 15px;
font-weight: 100;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: subpixel-antialiased;
letter-spacing: 0.075em;
background-color: #cccccc;
color: #000000;
perspective-origin: center 61.290322581vmin;
perspective: 100vmin;
}
main {
height: 100vmin;
width: 162vmin;
position: fixed;
margin: 0 auto;
top: 0;
left: 50%;
transform-style: preserve-3d;
transform: translate3d(-50%, 0, 0);
}
section {
position: absolute;
top: 0;
height: 100%;
width: 100%;
}
section:nth-child(1) {
transform: translate3d(0, 0, 0vmin);
}
section:nth-child(2) {
transform: translate3d(0, 0, -163.157894737vmin);
}
section:nth-child(3) {
transform: translate3d(0, 0, -592.520775623vmin);
}
section:nth-child(4) {
transform: translate3d(0, 0, -1722.423093745vmin);
}
section:nth-child(5) {
transform: translate3d(0, 0, -4695.850246699vmin);
}
section:nth-child(6) {
transform: translate3d(0, 0, -12520.658543944vmin);
}
section:nth-child(1) *:not(.empty) {
background-color: rgba(70, 130, 180, .5)
}
section:nth-child(2) *:not(.empty) {
background-color: rgba(0, 128, 0, .5)
}
section:nth-child(3) *:not(.empty) {
background-color: rgba(128, 0, 128, .5)
}
section:nth-child(4) *:not(.empty) {
background-color: rgba(70, 130, 180, .5)
}
section:nth-child(5) *:not(.empty) {
background-color: rgba(0, 128, 0, .5)
}
section:nth-child(6) *:not(.empty) {
background-color: rgba(128, 0, 128, .5)
}
header {
height: 38%;
width: 100%;
}
aside,
div {
height: 38%;
width: 31%;
float: left;
}
div {
width: 38%;
background-color: transparent;
}
footer {
clear: left;
height: 24%;
width: 100%;
}
#scroll {
display: block;
}
<body>
<main>
<section>
<header></header>
<aside></aside>
<div class="empty"></div>
<aside></aside>
<footer></footer>
</section>
<section>
<header></header>
<aside></aside>
<div class="empty"></div>
<aside></aside>
<footer></footer>
</section>
<section>
<header></header>
<aside></aside>
<div class="empty"></div>
<aside></aside>
<footer></footer>
</section>
<section>
<header></header>
<aside></aside>
<div class="empty"></div>
<aside></aside>
<footer></footer>
</section>
<section>
<header></header>
<aside></aside>
<div class="empty"></div>
<aside></aside>
<footer></footer>
</section>
</main>
<div id="scroll"></div>
</body>
问题在于我无法管理translateZ以使整个事物直线移动,它有点向下(与z轴成一个角度)。即使身体上有perspective-origin: center center
(而不是当前值)。
任何人都知道发生了什么事?
我想要实现的效果可以在这里看到:http://2011.beercamp.com/
但在我的尝试中,滚动缩小(它应该直接通过所有“窗口”):