记得前几年手机版淘宝左下角有个狠有意思的圆形按钮,点击后会出现几个小按钮,而且出场动画颇有意思,后面才知道这种效果叫“粘滞”效果,如图:css
那这种效果到底用了什么属性呢?答案是主要用了filter:blur()
属性,及filter:contrast()
属性配合动画
<style> body{ margin: 0; padding: 0; } .box{ position: relative; width: 500px; height: 500px; filter: contrast(20); /* 背景色必定要为实底色,不然两个元素边缘会有模糊效果 */ background-color: #fff; } .circle-big{ position: absolute; top: 20px; left: 100px; width: 100px; height: 100px; border-radius: 50%; filter: blur(6px); box-sizing: border-box; animation: toRight 3s ease-out infinite; background-color: #333; } .circle-small{ position: absolute; top: 35px; left: 220px; width: 60px; height: 60px; border-radius: 50%; filter: blur(6px); box-sizing: border-box; animation: toLeft 3s ease-out infinite; background-color: #FFFC00; } @keyframes toRight{ 50%{ left: 150px; } } @keyframes toLeft{ 50%{ left: 150px; } } </style> <div class="box"> <div class="circle-big"></div> <div class="circle-small"></div> </div>
最终效果如图:spa