(编辑:jimmy 日期: 2024/10/30 浏览:2)
上一次有一位非常好学的粉丝儿问可不可以把月亮做一个呼吸灯效果,因为没有找到月亮大小的图,就用星星代替
今天,本博主用纯css和flutter动画分别实现它,记得收藏学习哦
效果:
想要测试的,原图在文章末尾
实现原理:
准备两张图,让两张图交替出现。
纯css实现,代码如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; } .wrap{ width: 300px; height: 300px; position: relative; margin: 0 auto; overflow: hidden; } .img1, .img2{ margin-top: 100px; width: 100px; position: absolute; } .img2{ -webkit-animation: breath 3s infinite ease-in-out alternate; animation: breath 3s infinite ease-in-out alternate; } @-webkit-keyframes breath { 0% {opacity: .2;}60% {opacity: 1;}to {opacity: .2;} } @keyframes breath { 0% {opacity: .2;}60% {opacity: 1;}to {opacity: .2;} } </style> </head> <body> <div class="wrap"> <img src="images/star1.jpg" alt="底图" class="img1"> <img src="images/star2.jpg" alt="上图" class="img2"> </div> </body> </html>