css涟漪光圈扩散_CSS3 动画实现放大缩小、涟漪扩散效果、叠加图片循环来回显示...

一、无限放大缩小,可以应用于跳动的气球等场景,效果如下

这里写图片描述

html部分

1

2

css部分

@keyframes scaleDraw {  /*定义关键帧、scaleDrew是需要绑定到选择器的关键帧名称*/

0%{

transform: scale(1);  /*开始为原始大小*/

}

25%{

transform: scale(1.1); /*放大1.1倍*/

}

50%{

transform: scale(1);

}

75%{

transform: scale(1.1);

}

}

.ballon{

width: 150px;

height: 200px;

background: url("images/balloon.png");

background-size: 150px 200px;

-webkit-animation-name: scaleDraw; /*关键帧名称*/

-webkit-animation-timing-function: ease-in-out; /*动画的速度曲线*/

-webkit-animation-iteration-count: infinite;  /*动画播放的次数*/

-webkit-animation-duration: 5s; /*动画所花费的时间*/

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

上面的几个属性也可以合在一起写

-webkit-animation: scaleDraw 5s ease-in-out infinite;

1

二、涟漪扩散, 效果图如下

这里写图片描述

实质就是就是利用了动画的延迟属性,两层圆的动画相关的属性基本相同,除了最外层的圆多设置了animation-delay属性

html部分

        

1

2

3

4

5

6

css部分

.live{

position: relative;

width: 100px;

height: 100px;

}

.live img{

width: 100px;

height: 100px;

z-index: 0;

}

@keyframes living {

0%{

transform: scale(1);

opacity: 0.5;

}

50%{

transform: scale(1.5);

opacity: 0;   /*圆形放大的同时,透明度逐渐减小为0*/

}

100%{

transform: scale(1);

opacity: 0.5;

}

}

.live span{

position: absolute;

width: 100px;

height: 100px;

left: 0;

bottom: 0;

background: #fff;

border-radius: 50%;

-webkit-animation: living 3s linear infinite;

z-index: -1;

}

.live span:nth-child(2){

-webkit-animation-delay: 1.5s; /*第二个span动画延迟1.5秒*/

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

三、叠加图片循环来回显示,效果如下

这里写图片描述

思路:将第二张图片用绝对定位叠加在第一张图片上,通过在动画函数里设置透明度来控制图片的显示隐藏

html部分

        

        

1

2

3

4

5

css部分

.pics{

position: relative;

width: 400px;

height: 400px;

}

.pic1{

width: 400px;

height: 400px;

}

@keyframes picDraw {

0%{

opacity: 0;

}

50%{

opacity: 1;

}

100%{

opacity: 0;

}

}

.pic2{

position: absolute;

width: 400px;

height: 400px;

left: 0;

top: 0;

-webkit-animation: picDraw 5s ease-in-out infinite;

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,这里给你提供一种使用自定义类名和animate.css动画库给一张图片添加入场动画的示例。使用animate.css可以方便地实现CSS动画效果,具体可以根据需求自定义。 首先,需要在HTML文件中引入animate.css的CDN链接: ```html <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" /> ``` 然后,HTML代码如下: ```html <div class="image-wrapper animate__animated"> <img src="image.jpg" alt="图片"> </div> ``` CSS代码如下: ```css .image-wrapper { position: relative; display: inline-block; } .image-wrapper.animate__animated { animation-duration: 1s; /* 设置动画持续时间 */ animation-delay: 0.5s; /* 设置动画延迟时间 */ animation-fill-mode: both; /* 设置动画结束后保持最后状态 */ animation-name: slideInLeft; /* 设置动画名称 */ } @keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } } .image-wrapper img { display: block; max-width: 100%; height: auto; } ``` 这段代码使用了animate.css库中的slideInLeft动画效果,通过给`.image-wrapper`添加类名`.animate__animated`来触发动画效果。其中,`.image-wrapper.animate__animated`使用了CSS3动画属性animation,通过设置animation-duration、animation-delay、animation-fill-mode、animation-name属性来定义动画效果。同时,利用@keyframes定义了从左侧平移进入的动画效果。最后,`.image-wrapper img`设置了图片的基本样式,其中max-width: 100%可以确保图片的宽度不会超出其容器的宽度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值