gpt4 book ai didi

javascript - Tab 内的 HTML 加载器

转载 作者:太空宇宙 更新时间:2023-11-04 01:10:41 25 4
gpt4 key购买 nike

下面的代码由一个选项卡和一个 html 加载器动画组成。我目前已将 loader 放在我的 tab 中,我想要完成的是,只要选项卡中的内容完全加载,html loader 动画就会消失.

这是实现此目标的简单方法吗?非常感谢任何帮助。

function openCity(evt, cityName) {
var i, tabcontent, tablinks;

tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}

tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}

document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
document.getElementById("defaultOpen").click();
body {
font-family: Arial;
}

/* Style the tab */
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}

/* Style the buttons inside the tab */
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}

/* Change background color of buttons on hover */
.tab button:hover {
background-color: #ddd;
}

/* Create an active/current tablink class */
.tab button.active {
background-color: #ccc;
}

/* Style the tab content */
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}

.loader {
border: 10px solid #f3f3f3;
border-radius: 50%;
border-top: 10px solid #05788C;
border-bottom: 10px solid #05788C;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
margin: auto;
margin-top: 30px;
margin-bottom: 30px;
}

@-webkit-keyframes spin {
0% {
-webkit-transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
}
}

@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
<!DOCTYPE html>

<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>

<body>

<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')" id="defaultOpen">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>

<div id="London" class="tabcontent">
<div class="loader">
<iframe width="560" height="315" src="https://www.youtube.com/embed/wowAOdTYqw8" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
</div>

<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>

<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
</body>

</html>

最佳答案

我已经完成了以下 CSS 方法:

<div class="holds-the-iframe"><iframe here></iframe></div>
.holds-the-iframe {background:url(../images/loader.gif) center center no-repeat;}

或将 div class 名称更改为您的类名称“loader”。

<div id="London" class="tabcontent">
<div class="loader">
<iframe width="560" height="315" src="https://www.youtube.com/embed/wowAOdTYqw8" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
</div>

关于javascript - Tab 内的 HTML 加载器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51257087/

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