帝王谷资源网 Design By www.wdxyy.com

记得前几年手机版淘宝左下角有个狠有意思的圆形按钮,点击后会出现几个小按钮,并且出场动画很有意思,后面才知道这种效果叫“粘滞”效果,如图:
 

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>

最终效果如图:
 

CSS实现两个元素相融效果(粘滞效果)

标签:
CSS,元素相融,粘滞效果

帝王谷资源网 Design By www.wdxyy.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
帝王谷资源网 Design By www.wdxyy.com