css----动画(图片无限放大缩小)

先给大家推荐animate.css库,里面有一些效果很不错的过度样式,不想自己写的也可以直接安装这个库来使用,如果不想安装这个库也可以去https://daneden.github.io/animate.css/挑选自己喜欢的样式之后F12复制相应的样式代码或者该网站里面也有源码可以复制。这个库的安装及用法直接百度结果有很多。

样式一:效果如下

 

<div class="ballon"></div>
/*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; /*动画所花费的时间*/ }

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

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

样式二:效果如下

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

 <div class="live">
         <img src="images/live.png" alt="">
         <span></span>
         <span></span>
 </div>
.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秒*/
        }

样式三:效果如下

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

   <div class="pics">
         <img src="images/avatar1.png" alt="" class="pic1">
         <img src="images/avatar2.png" alt="" class="pic2">
   </div>
.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;
        }

原文链接:https://blog.csdn.net/yujin0213/article/details/79262825

原文地址:https://www.cnblogs.com/humiao-0626/p/11993515.html