2-19 课上代码实现效果,请老师帮忙检查一下有无失误,谢谢
来源:2-19 动画效果实战课
呜蜩的呀
2022-08-01 18:29:40
相关代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
div {
width: 500px;
height: 600px;
border: 1px solid #000;
margin: 40px auto;
background-color: rgba(0, 0, 0, 0.265);
position: relative;
}
.box img {
position: absolute;
}
.box img.dengpao {
width: 193px;
height: 267px;
top: 50%;
margin-top: -133.5px;
left: 50%;
margin-left: -96.5px;
}
.box img.dengg {
width: 343px;
height: 256px;
top: 100px;
left: 75px;
/* 调用动画,infinite表示动画永不停止,alternate表示动画循环进行 */
animation: twinkle .8s linear 0s infinite alternate;
}
/* 问题:当有两个对象时,动画效果应该写在那个对象上面?还是说两个对象都要写上? */
/* 定义灯泡闪烁的动画 */
/* opacity的属性值是只有0或者1吗?透明或者不透明?还是0~1之间的范围值?大于1的数值会是什么反应? */
@keyframes twinkle {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
/* 火箭宇宙穿梭效果 */
.huojian {
width: 250px;
height: 220px;
top: 50%;
margin-top: -110px;
left: 50%;
margin-left: -125px;
opacity: 1;
/* 调用动画效果并且永不停止循环反复 */
animation: move .8s linear 0s infinite alternate;
}
/* 定义背景的线条 */
.bgline {
width: 2px;
height: 126px;
background-color: aquamarine;
border: none;
transform: rotate(45deg);
/* opacity: 0; */
position: absolute;
top: -100px;
left: 400px;
/* 调用线条运动的动画 */
animation: linemove .925s ease 0s infinite;
}
.no1 {
top: 100px;
left: 350px;
animation: linemove .925s ease .3s infinite;
}
.no2 {
top: 160px;
left: 240px;
animation: linemove .925s ease .6s infinite;
}
.no3 {
top: 270px;
left: 440px;
animation: linemove .925s ease .97s infinite;
}
/* /定义背景线条的运动 */
@keyframes linemove {
0% {
transform: rotate(45deg) translateY(-10px);
opacity: 0;
}
50% {
transform: rotate(45deg) translateY(75px);
opacity: 1;
}
100% {
transform: rotate(45deg) translateY(200px);
opacity: 0;
}
}
/* 定义火箭摇摆的动画 */
@keyframes move {
from {
transform: translateX(-100px) translateY(-100px);
}
to {
transform: translateX(100px) translateY(150px);
}
}
</style>
</head>
<body>
<!-- 发光的灯泡 -->
<div class="box">
<img class="dengpao" src="../作业素材/images/dengpao.png" alt="dengpao">
<img class="dengg" src="../作业素材/images/guang.png" alt="light">
</div>
<!-- 宇宙穿梭 -->
<div class="box">
<img class="huojian" src="../作业素材/images/huojian.png" alt="huojian">
<div class="bgline"></div>
<div class="bgline no1"></div>
<div class="bgline no2"></div>
<div class="bgline no3"></div>
</div>
</body>
</html>1回答
好帮手慕慕子
2022-08-01
同学你好,效果实现是可以的,代码中注释的问题解答如下:
1、写在需要有动画效果的对象上,如果两个都需要动画,那么就两个对象都写上。
2、0~1之间的范围值。大于1之后,与设置为1的值表现一样。
祝学习愉快~
相似问题
回答 1