gpt4 book ai didi

html - 固定位置透视

转载 作者:太空宇宙 更新时间:2023-11-04 02:02:18 26 4
gpt4 key购买 nike

这是我的 JS FIDDLE

我想要我的 div id="text"固定。但它不适用于我的代码...问题是我需要将所有内容保留在我的 div id="wrapper" 中.我能怎么做?如果您有其他解决方案可以对我的图像产生视差效果(仅使用 css),请告诉我。

body {
overflow-x: hidden;
margin:0;
}

#text {
font-size: 70px;
height: 100%;
width: 100%;
position: fixed;
}
#intro {
font-size: 30px;
width: 100%;
border:3px solid yellow;
position: absolute;
}

#wrapper {

transform-style: preserve-3d;
height: 100%;
perspective: 1px;
overflow-x: hidden;
border:3px solid cyan;
position: fixed;
top: 0;
left: 0;
width: 100%;

}

#wrapper section {

position: relative;
height: 200px;
width: 300px;
background:pink;
box-sizing: border-box;
border:3px solid red;
transform-style: inherit;
overflow: hidden;
margin: 100px;

}

#wrapper section .back {
width: 300px;

border:3px solid green;
transition: transform 1s ease-out;
height:200px;
background-position: center center;
transform: translateZ(-0.6px) scale(1.5); }

.back {
background-image: url(http://wallpaper-gallery.net/images/background-image/background-image-18.jpg); }





#wrapper section .back:hover {

opacity: 0.5;
transform:translateZ(-0.4px) scale(2.6); }

最佳答案

这里是:

body {
overflow-x: hidden;
/* position:static;*/
margin:0;

}

#text {
font-size: 70px;
height: 100%;
width: 100%;
position: fixed;
pointer-events: none;
}
#intro {
font-size: 30px;
width: 100%;
border:3px solid yellow;
position: absolute;
}

#wrapper {

transform-style: preserve-3d;
height: 100%;
perspective: 1px;
overflow-x: hidden;
border:3px solid cyan;
position: fixed;
top: 0;
left: 0;
width: 100%;

}

#wrapper section {

position: relative;
height: 200px;
width: 300px;
background:pink;
box-sizing: border-box;
border:3px solid red;
transform-style: inherit;
overflow: hidden;
margin: 100px;

}

#wrapper section .back {
width: 300px;

border:3px solid green;
transition: transform 1s ease-out;
height:200px;
background-position: center center;
transform: translateZ(-0.6px) scale(1.5); }

.back {
background-image: url("http://wallpaper-gallery.net/images/background-image/background-image-18.jpg"); }





#wrapper section .back:hover {

opacity: 0.5;
transform:translateZ(-0.4px) scale(2.6); }
<div id="wrapper">
<div id="intro">
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
</div>
<section id="frame1"><div class="back"></div></section>
<section id="frame3"><div class="back"></div></section>
<section id="frame5"><div class="back"></div></section>
<section id="frame7"><div class="back"></div></section>
</div>
<div id="text">
<h1>Hello</h1>
</div>

您需要将 real fixed 元素放在 DOM 的最后(作为 #wrapper 的兄弟)并给它 pointer -events:none 所以它允许 pointer-events(包括 scroll)传递给另一个 fixed 定位元素(#wrapper,它包含其余内容)需要滚动才能使视差效果发生。

关于html - 固定位置透视,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41539001/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com