gpt4 book ai didi

html - 在右手 div 完成滚动之前,如何修复左手 DIV

转载 作者:行者123 更新时间:2023-11-28 15:21:19 25 4
gpt4 key购买 nike

我有一个包含三个部分的测试网页。第一和第三部分都是整页大小(100% 宽度和高度)。然而,中间部分被分成两半,左边是标题,右边是内容。我想要实现的是,当您滚动到第二部分时,当它滚动到屏幕顶部时,左侧会锁定到位,然后在右侧的内容通过后继续滚动。

到目前为止,我已经尝试使用 Bootstraps 词缀属性来实现这一点,但无论我尝试什么,似乎都无法让它发挥作用。这是我的测试标记...

<!DOCTYPE html>
<html lang="en">
<head>
<title>TEST</title>
<link href="style.css" rel="stylesheet">
</head>
<body>

<!-- Section 1 -->
<section class="fullpage" style="background-color:#0ff;">
</section>

<!-- Section 2 -->
<section class="fullpage">

<div class="sectiontitle">
<h1>THIS SHOULD STAY IN PLACE</h1>
<h1>UNTIL GREEN GETS TO BOTTOM</h1>
</div>

<div class="sectiondetail">
<p>Hello world this is a test</p><p>Hello world this is a test</p><p>Hello world this is a test</p>
</div>

</section>

<!-- Section 3 -->
<section class="fullpage" style="background-color:#ff0;">
</section>

</body>
</html>

还有我正在使用的 CSS...

html, body{
height:100%;
margin:0;
padding:0;
}
h1, h2, h3, p{
margin:0;
padding:0;
}
h1{
padding:50px 0 50px 50px;
}
p{
padding:20px;
}

.fullpage{
min-height:100vh;
width:100%;
position:relative;
display:block;
}

.sectiontitle{
position:absolute;
width:50%;
left:0px;
background-color:#f00;
height:100vh;
}

.sectiondetail{
position:relative;
width:50%;
left:50%;
background-color:#0f0;
height:200vh;
}

我实际上更喜欢使用 Bootstrap,但是是否有一种仅使用 CSS 和/或 JQuery 来实现此目的的简便方法?

编辑:找到这个页面,它做的事情与我正在寻找的类似。只需向下滚动到第一页以外。

Example website with required behaviour

提前致谢,西蒙

最佳答案

你可以尝试按照纯 css 的想法来调整 z-indexes。如果你需要更平滑和干净的效果,你可以使用 jquery 或视差插件

html,
body {
height: 100%;
margin: 0;
padding: 0;
}
h1,
h2,
h3,
p {
margin: 0;
padding: 0;
}
h1 {
padding: 50px 0 50px 50px;
}
p {
padding: 20px;
}
.fullpage {
min-height: 100vh;
width: 100%;
position: relative;
display: block;
}
.sectiontitle {
position: absolute;
width: 50%;
left: 0px;
background-color: #f00;
height: 100vh;
}
.sectiondetail {
position: relative;
width: 50%;
left: 50%;
height: 100vh;
}
.magic {
width: 100%;
position: absolute;
top: 0;
left: 0;
z-index: 999;
overflow-x: scroll;
overflow-y: none;
}
<section class="fullpage" style="background-color:#0ff;">
</section>

<!-- Section 2 -->
<section class="fullpage" style="position:relative;background:green;">

<div class="sectiontitle">
<h1>THIS SHOULD STAY IN PLACE</h1>
<h1>UNTIL GREEN GETS TO BOTTOM</h1>
</div>
<div class="magic">
<div class="sectiondetail">
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
<p>Hello world this is a test</p>
</div>

</div>

</section>

<!-- Section 3 -->
<section class="fullpage" style="background-color:#ff0;">
</section>

关于html - 在右手 div 完成滚动之前,如何修复左手 DIV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34452580/

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