javascript - 滑块移动时使文本消失
问题描述
如您所见,我用 HTML 和 CSS 制作了一个图像滑块。问题是我无法使第一个滑块图像上的文本消失。
HTML:
<div class="slider-frame">
<div class="slider-images">
<div class="image-container">
<img src="./Images/Image1.jpg">
<h2 class="first-img-main-text">Main Text</h2>
<p class="first-img-text">Caption</p>
<a class="first-img-btn">Button</a>
</div>
</div>
</div>
CSS:
.image-container img {
width: 1681px;
height: 750px;
animation-name: slide_animation;
animation-duration: 25s;
animation-iteration-count: infinite;
@keyframes slide_animation {
0% {transform: translateX(0);}
11% {transform: translateX(0);}
22% {transform: translateX(-100%);}
33% {transform: translateX(-100%);}
44% {transform: translateX(-200%);}
55% {transform: translateX(-200%);}
66% {transform: translateX(-100%);}
77% {transform: translateX(-100%);}
88% {transform: translateX(0);}
100% {transform: translateX(0);}
}
老实说,我不知道如何使用 JavaScript。
JavaScript:
// Button
const firstImageBtn = document.querySelector('.first-img-btn');
// Text
const mainText = document.querySelector('.first-img-main-text');
const caption = document.querySelector('.first-image-text');
// Animations
const slideAnimation = document.getAnimations('slide_animation');
// Event Listeners
// Button Animations
firstImageBtn.addEventListener('mouseover', function(){
firstImageBtn.style.background = '#000';
firstImageBtn.style.transition = '0.6s';
});
firstImageBtn.addEventListener('mouseout', function(){
firstImageBtn.style.background = 'none';
firstImageBtn.style.transition = '0.4s';
});
// Text Animations
mainText.addEventListener('change', function(){
if (slideAnimation.style.transform <= 'translateX(-20%)') {
mainText.style.filter = 'opacity(0)';
}
});
解决方案
推荐阅读
- python - 使用正则表达式将自由文本解析为 dict
- java - 调用菜单视图时出错
- git - 如果我永远不会在它们之间合并,那么在两个分支 A 和 B 之间的 git 中采摘樱桃有什么危险?
- c# - .Net Crystal Reports 13 可以使用应用程序池身份登录 SQL Server 吗?
- c# - 如何在c#中获取像素颜色
- javascript - 使用 php 过滤 CRUD 表
- java - 分组字符串 - Java
- spring-boot - Grafana singlestat 和 transformNull
- javascript - 无法使用 .not() 或 :not 正确
- c# - UWP Storyboard 和 CallMethodAction 的仅发布例外