html - 如何通过单击 image3 来影响两个元素(image1 和 image2)
问题描述
我有一个不能使用 Javascript 的学校项目。只是HTML
和CSS
。主题是Lucky Luke
,我正在尝试制作动画,每当我单击另一个对象时,他就会在其中拍摄。
这个想法是让两张图像相互叠加,其中一张不可见,而另一张在我拍摄物体时可见,我点击的物体是触发器。
然后,这两个图像应在短时间内恢复到其原始不透明状态。
#luckyStand {
position: absolute;
opacity: 1;
bottom: 0;
left: -250px;
}
#luckyShoot {
position: absolute;
opacity: 0;
bottom: 0;
left: -250px;
}
#db1 {
position: absolute;
top: 165px;
right: 370px;
}
#db1:target~#luckyShoot {
opacity: 1;
}
<div id="db1">
<a href="#db1">
<img src="images/dalton_brother1.png">
</a>
</div>
<div id="luckyStand">
<img src="images/lucky_luke_idle.png">
</div>
<div id="luckyShoot">
<img src="images/lucky_luke_shooting.png">
</div>
解决方案
您可能想使用关键帧动画:
#luckyShoot {
opacity: 0;
animation-duration: 2s; /* length of time to show the element before it disappears again */
animation-fill-mode: forwards;
}
#db1:target~#luckyShoot {
animation-name: fadeInOut;
}
@keyframes fadeInOut {
0% {
opacity: 1; /* will show immediately */
}
99% {
opacity: 1; /* for 99% of the animation duration (2s) */
}
100% {
opacity: 0; /* will hide at the end */
}
}
<div id="db1">
<a href="#db1">
<img src="images/dalton_brother1.png">
</a>
</div>
<div id="luckyStand">
shown
</div>
<div id="luckyShoot">
start hidden
</div>
推荐阅读
- fonts - 如何将字体添加到 abcpdf 7
- reactjs - 为什么我在 react-intl V3.2.2 中出现解析错误?
- json - KeyError:python3中的“数据”
- mongodb - 按 MongoDB 中的字段对它们进行分组后选择最新文档
- python - 有什么方法可以在 Python 中为日志记录模块配置缓冲区
- java - C 服务器与 Java 客户端套接字连接。在客户端上阅读消息时,我在实际消息之前看到空格
- excel - 关闭文件后终止在后台保持打开状态的 Excel 进程
- c++ - std::bind 与可变参数模板成员函数和通用引用
- c++ - C++ 析构函数和所有权
- objective-c - 分离由 CGWindowListCopyWindowInfo 返回的真实和虚拟窗口