登录  /  注册
首页 > web前端 > css教程 > 正文

css实现圆与边框旋转动画的代码实例

不言
发布: 2018-09-18 14:54:13
原创
2797人浏览过

本篇文章给大家带来的内容是关于css实现圆与边框的代码实例,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

实现效果:

524676735-5b9fcb7ccb79d_articlex.png

代码

html:

<div>
    <div>
        <div> </div>
    </div>
    <div>
    </div>
    <div>
    </div>
</div>
登录后复制

css:

     #box {
        height:200px;
        width:200px;
    }

    .circle-out{
        height: inherit;
        width: inherit;

        display: inline-block;
        text-align: center;

        border: 20px solid blue;
        border-radius: 50%;
        
    }

    /* 绘制弧形 */
    .circle-part{
        display: inline-block;
        position: relative;
        width:0px;
        height: 0px;

        border-radius: 50%;
        border: 100px solid #0000ff05;
        border-top: 100px solid blue;

        top: -220px;
        left: 20px;

        transform: rotate(0deg);
        animation: run-part 5s infinite;
    }

    .part1{
        height: 0px;
        width: 0px;

        border-radius: 50%;
        border:100px solid #fafafa;
        border-top: 100px solid #ff000000;

        position: relative;
        top: -420px;
        left: 20px;

        transform: rotate(45deg);
        animation: run-part1 5s infinite;
    }

    .circle-inner{
        height: 0px;
        width: 0px;
        display: inline-block;

        border-radius: 50%;
        border: 20px solid blue;

        top: 80px;
        position: relative;
        
        z-index: 1000;
    }

    @-webkit-keyframes run-part1{
        0%{
            transform: rotate(45deg);
        }

        100% {
            transform: rotate(405deg);
        }
    }

    @-webkit-keyframes run-part{
        0%{
            transform: rotate(0deg);
        }

        100% {
            transform: rotate(360deg);
        }
    }
登录后复制

实现思路

1 图形构成

从外观看到,该图形大致由:外圆,内圆及构扇形构成。

1.1 外圆

在本示例中,主要采用一个p,设置高与宽,背景不设置或白色。设置 border-radius为50%外圆圈,使用边框构成从而形成外圈。

.circle-out{
    height: inherit;
    width: inherit;
    border: 20px solid blue;
    display: inline-block;
    border-radius: 50%;
    text-align: center;
}
登录后复制

效果图

3291946171-5b9fcb7d3ff68_articlex.png

1.2内圆

内圆很简单,也是使用border完成的圆,设置boder-radius:50%实现的圆的效果,最后就是一个定位的事情。

1.3扇形

扇形,在本示例中,实现的思路也是拼凑,外加旋转,利用边框border实现。

  .circle-part{
        //(1)
        display: inline-block;
        width:0px;
        height: 0px;

        //(2)
        border-radius: 50%;
        border: 100px solid #0000ff05;
        border-top: 100px solid blue;
        
        //(3)
        position: relative;
        top: -220px;
        left: 20px;

        //(4)
        transform: rotate(0deg);
        animation: run-part 5s infinite;
    }
登录后复制

如上代码:
分为(1)、(2)、(3)、(4)部分,出去固定形状、动画外,比较重要的就在于(2)部分。

先绘制出1/4的圆(边框)。其他另外3/4的扇形以透明绘制。

相同的,另外使用另外一个圆进行相同的处理,这样两个圆就能重叠在一起,唯一不同的是:第二个圆设置那3/4圆作为白色,1/4设置为透明色。

这时,呈现的为1/4的扇形,背景为blue,而因为透明的原因1/4是完全暴露的。

最后,由于最后的圆为顶层元素,所以当顶层元素发生旋转时,蓝色的扇形部分就会被顶层元素那3/4的扇形区域所遮蔽。从而达到最后的效果。

代码最后加上自己的动画,实现最后的效果。


以上就是css实现圆与边框旋转动画的代码实例的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号