在CSS中,可以使用animation属性、“@keyframes”规则、transform: scale()实现图片放大缩小动画。
示例1:
<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; /*动画所花费的时间*/ }
上面的几个属性也可以合在一起写
animation: scaleDraw 5s ease-in-out infinite; -webkit-animation: scaleDraw 5s ease-in-out infinite;
效果:
实例2:
<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秒*/ }
实质就是就是利用了动画的延迟属性,两层圆的动画相关的属性基本相同,除了最外层的圆多设置了animation-delay属性
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)