gpt4 book ai didi

javascript - 在到达页面底部之前显示 div 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 07:49:27 24 4
gpt4 key购买 nike

我在另一个 div 前面显示一个 div,以显示一个带有 observable 的加载 div;问题是,当加载 div 显示时它会增长并出现“丑陋的滚动条”,是否可以只显示加载 div 直到它到达页面底部。

<html> 
<head>
<title>Hello loading div</title>
</head>
<body>
<div class="container">
<div class="nav-bar">
<button data-bind= "click: startLoading">Start loading</button>
<button data-bind= "click: stopLoading">Stop loading</button>
</div>
<div class="content">
<div class="tab-content">
<!-- ko if: tabLoading -->
<div class="tab-loading-mask" id="tab-loading-mask-edit"></div>
<!-- /ko -->
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
</body>
</html>

我的代码示例在这里:https://codepen.io/the-writer/pen/NXNLob ,我没有添加 knockout js 标签,因为我只使用这个库的可观察对象。

最佳答案

因为 .tab-loading-maskposition: absolute; 它的父级需要 position: relative;

position: absolute; 元素相对于它们最近的父元素定位

// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
this.tabLoading = ko.observable(false);
this.startLoading = () => {
this.tabLoading(true);
console.log("Start");
}

this.stopLoading = () => {
this.tabLoading(false);
console.log("Stoped");
}
}

// Activates knockout.js
ko.applyBindings(new AppViewModel());
.nav-bar {
height: 200px;
background-color: green;
}

.content {
position: relative;
}


.tab-loading-mask {
position: absolute;
width: 100%;
height: 100%;
z-index: 100;
background: rgba(0, 0, 0, 0.25);
overflow: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<html>
<head>
<title>Hello loading div</title>
</head>
<body>
<div class="container">
<div class="nav-bar">
<button data-bind= "click: startLoading">Start loading</button>
<button data-bind= "click: stopLoading">Stop loading</button>
</div>
<div class="content">
<div class="tab-content">
<!-- ko if: tabLoading -->
<div class="tab-loading-mask" id="tab-loading-mask-edit"></div>
<!-- /ko -->
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
</div>
</div>
</div>
</body>
</html>

关于javascript - 在到达页面底部之前显示 div 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47896165/

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