gpt4 book ai didi

javascript - 如何使用
    显示滚动内容?

转载 作者:技术小花猫 更新时间:2023-10-29 12:18:04 26 4
gpt4 key购买 nike

我遇到了 https://minimill.co/并将其视为我正在努力实现的目标的一个很好的例子。

我试图显示列表中的元素,如网站:

.wrap {
display: block;
list-style: none;
position: relative;
padding: 0;
margin: 0;
border: 0;

li {
background-color: green;
}
}

.content {
margin: 0 auto;
max-width: 66rem;
width: 90%;
padding: 0;
border: 0;
position: relative;
}

.right-details {
display: inline-block;
float: right;
box-size: border-box;
width: 33.33333%;
}

.left-img {
display: inline-block;
float: left;
box-sizing: border-box;
width: 66.66666%;

img {
width: 50px;
}
}
<ul class="wrap">
<li>
<div class="content">
<div class="left-img">
<img src="/assets/img/macbook-image.png"/>
</div>
<h2 class="right-details">
Item 1
</h2>
</div>
</li>
<li>
<div>
<h2>
Item 2
</h2>
</div>
</li>
</ul>

但是第一个<li>消失。

如何在一个长卷轴中显示我的内容如何https://minimill.co/是在做?我在网站上执行的是否正确?任何有关更紧密地模仿它的指导或见解将不胜感激。

最佳答案

您应该使用 min-height:100vh 而不是 height:100vh;。请查看我的fiddle

// select all elements with data-background attribute
var lis = document.querySelectorAll("[data-background]");
// create empty array
var heights = [];
// use for loop to "discover" all of the elements in lis array
for(var i = 0; i < lis.length; i++){
// get element's distance from top
var distanceFromTop = lis[i].offsetTop;
// get value from data-backgrount attribute
var background = lis[i].getAttribute("data-background");
// push background and distance to heights array
heights.push({background: background, distance: distanceFromTop});
};

// check if page was scrolled
window.addEventListener("scroll", function(evt){
// if page was scrolled what's the user's distance from top
var distanceFromTop = this.scrollY;

// find distances in heights array
heights.forEach(function(height) {
// check if user reached another checkpoint
if(height.distance < distanceFromTop) {
// if so, change the background to value that we got from data-background attribute
//
document.body.className = height.background;
}
});
});
body {
transition: background-color .8s ease;
-webkit-transition: background-color .8s ease;
}

body.blue { background-color: #39f; }
body.red { background-color: #FF351A; }
body.dark { background-color: #222; }
body.yellow { background-color: #fd3; }
body.deep-blue { background-color: #417ABA; }
body.white { background-color: #fff; }
body.beige { background-color: #F7D693; }

li {
min-height: 100vh;
list-style-type:none;
}
<body class="blue">
<ul>
<li data-background="blue"></li>
<li data-background="red"></li>
<li data-background="dark"></li>
<li data-background="yellow"></li>
<li data-background="deep-blue"></li>
<li data-background="white"></li>
<li data-background="beige"></li>
</ul>
</body>

您应该使用 min-height:100vh 而不是 height:100vh;。请查看我的fiddle

关于javascript - 如何使用<ul>显示滚动内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42235470/

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