每天一点点之css - 动画-一个圆绕着另一个圆动(绕着轨迹运动)

本文介绍如何使用CSS3的动画属性实现小圆沿特定轨迹运动的星河效果。通过定义关键帧动画,使小圆围绕中心旋转,创建出迷人的视觉效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

最近要开发一个类似星河的效果,需要小圆绕着一定的轨迹运动,这个时候我首先想到的是使用canvas来实现,在实现过程中发现这个实现起来不是很灵活,然后想到css3有动画也可以实现,下面是效果

注:图2是多个的效果,没有代码 

 

html

<div class="s">
    <div class="m">
        <div class="small small1">
            <div class="small-p small-p1"></div>
        </div>
    </div>
</div>

 

css

.s {
        width: 500px;
        height: 200px;
        border: 1px solid #ccc;
        position: relative;
        left: 50px;
        top: 50px;
        overflow: hidden;
        margin-bottom: 100px;
    }
    
    .small-p{
        width: 10px;
        height: 10px;
        border-radius: 5px;
        background: #ff0000;
        position: absolute;
        
    }
    .small-p1 {
        background: #dde3a2;
        top: -5px;
        left: 150px;
    }
    .small {
        position: relative;
        width: 300px;
        height: 300px;
        border-radius: 150px;
        left: 100px;
        top: -50px;
        animation: run 6s linear infinite;
        border: 1px solid #dde3a2;
    }
    .m {
        position: absolute;
    }
    @keyframes run{
        0%{
            transform: rotateZ(0deg);
        }
        100%{
            transform: rotateZ(360deg);
        }
    }    

 

转载于:https://www.cnblogs.com/cap-rq/p/10201798.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值