AOS动画在改变制表符时不工作?



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;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://unpkg.com/aos@next/dist/aos.css" />
</head>
<body>
<p data-aos="zoom-out-up">In this example, we use JavaScript to "click" on the London button, to open the tab on page load.</p>
<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" data-aos="zoom-in">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent" data-aos="fade-down">
<h3>Paris</h3>
<p>Paris is the capital of France.</p> 
</div>
<div id="Tokyo" class="tabcontent" data-aos="flip-up">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
<script src="https://unpkg.com/aos@next/dist/aos.js"></script>
<script>
AOS.init();
</script>
</body>
</html>

我正在学习AOS动画。上面的代码是我尝试使用的示例代码。在加载过程中,动画为第一个选项卡内容工作。动画在第二个和第三个标签上不起作用。然后,当更改选项卡时,动画不工作。我没有使用任何额外的库。有什么建议吗?

AOS在元素进入垂直滚动视口时动画化。这就是为什么第一个选项卡在页面加载时是动画的,而其他隐藏的元素则没有;即使在它们变得可见之后。如果您希望在选项卡可见之后动画元素,您应该寻找另一个库,该库基于添加classes来动画元素,因此您可以通过编程方式添加适当的classes。我可以推荐animation .css

最新更新