css3动画之圆形运动轨迹

news/2024/7/8 7:52:49 标签: css3, 动画

css3中通过@keyframes定义动画,animation设置动画属性,从而实现动画效果;

在animation属性当中,可以规定动画的名称、整个动画的运行时间、运动的速度曲线以及其延迟时间、播放次数等。

animation

animation作为一个复合属性,包括了以下动画属性。

  • animation-name -------------------------------------规定动画名称

  • animation-duration ---------------------------------规定动画完成一次的时间

  • animation-timing-function  ----------------------规定动画的运动速度曲线

  • animation-delay  ------------------------------------规定动画的延迟时间

  • animation-iteration-count  -----------------------规定动画的播放次数

  • animation-direction   ------------------------------规定动画下一周期是否逆向开始

  • animation-fill-mode  -------------------------------规定动画时间之外的状态

  • animation-play-state  ------------------------------规定动画的运行和暂停

animation-timing-function

规定动画的速度曲线。默认是 "ease"。常用的运动速度曲线还有以下几种:

  • linear:线性过渡。
  • ease-in:由慢到快。
  • ease-out:由快到慢。
  • ease-in-out:由慢到快再到慢。

也可以直接使用贝塞尔曲线规定运行的速度曲线,贝塞尔曲线的4个数值需在[0, 1]区间内。

animation-direction

规定动画是否在下一周期逆向播放。默认是 "normal"

  • reverse:反方向运动
  • alternate:先正常方向再反方向运动,持续交替
  • alternate-reverse:先反方向再正常方向运动,持续交替

animation-fill-mode

规定对象动画时间之外的状态。常用值如下:

  • none:默认值
  • forwards:设置对象状态为动画结束时的状态
  • backwards:设置对象状态为动画开始时的状态

圆形运动轨迹

实现代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>沿圆形轨迹运动</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            height: 100%;
        }
        #trajectory {
            width: 300px;
            height: 300px;
            border: 4px solid #949494;
            border-radius: 50%;
            position: relative;
            left: calc(50% - 153px);
            top:calc(50% - 153px);
        }
        @keyframes moveX{
            0% {left: -22px;}
            100% {left: 282px;}
        }
        @keyframes moveY{
            0% {top: -22px;}
            100% {top: 282px;}
        }
        #move {
            width: 40px;
            height: 40px;
            font-size: 12px;
            background-color: #32c33a;
            border-radius: 50%;
            position: absolute;
            left:-22px;
            top:-22px;
            animation: moveX 4s cubic-bezier(0.36,0,0.64,1) -2s infinite alternate, moveY 4s cubic-bezier(0.36,0,0.64,1) 0s infinite alternate;
        }
    </style>
</head>
<body>
    <div id="trajectory">
        <div id="move">Immortal brother</div>
    </div>
</body>
</html>

 

 以上代码的注意点如下:

  • 对body高度100%的设置原因在于html5环境下body的默认高度为0
  • calc在使用过程中,值与值之间的“-”和“ ”两端的空格必不可少
  • 动画当中的left和top值为物体运动的起始位置和结束位置,要注意border值
  • 动画一次执行的运动轨迹仅为一半
  • 速度曲线:cubic-bezier(0.36,0,0.64,1);
  • 两个方向的延迟时间的设置 X:-2s;Y : 0s
  • 先正方向再反方向持续交替运行 :alternate

http://www.niftyadmin.cn/n/1733075.html

相关文章

海康威视SDK控制台程序consoleDemo获取视频通道参数

陈拓 2021/08/27-2020/08/27 1. 概述 在《海康威视SDK控制台程序consoleDemo》 https://zhuanlan.zhihu.com/p/403903892 https://blog.csdn.net/chentuo2000/article/details/119939573 一文中我们已经编译成功了海康威视SDK的控制台程序consoleDemo。在上文的基础上本文…

安装win7后鼠标一卡一卡

安装win7后鼠标一卡一卡的2009年11月01日 星期日 下午 02:04SL 400 AQC 安装win7后鼠标一卡一卡的win7 鼠标一卡一卡的解决办法winR打开运行窗口&#xff0c;输入services.msc&#xff0c;然后找到windows search服务&#xff0c;把它停掉

海康威视SDK控制台程序consoleDemo获取码流

陈拓 2021/08/28-2020/08/28 1. 概述 在《海康威视SDK控制台程序consoleDemo》 https://zhuanlan.zhihu.com/p/403903892 https://blog.csdn.net/chentuo2000/article/details/119939573 一文中我们已经编译成功了海康威视SDK的控制台程序consoleDemo。 在《海康威视SDK控…

box-shadow的应用技巧

一、box-shadow的参数解析 box-shadow:none; box-shadow: h-shadow v-shadow blur spread color inset; box-shadow参数解析 值描述none默认值&#xff0c;元素没有任何阴影效果。h-shadow阴影水平偏移量&#xff0c;其值可以是正负值。如果取正值&#xff0c;则阴影在元素的右…

jQuery对象与dom对象的转换

http://www.ccvita.com/192.html最近在闲暇时间用jQuery搞了一个多文件上传的东东&#xff0c;顺便写点笔记。 一直以来对于通过jQuery方式获取的对象使不能直接使用JavaScript的一些方法的&#xff0c;开始的时候不理解&#xff0c;现在此案知道&#xff0c;原来jQuery 获得的…

海康威视SDK控制台程序consoleDemo将实时码流保存为视频文件mp4

陈拓 2021/08/28-2020/08/29 1. 概述 在《海康威视SDK控制台程序consoleDemo》 https://zhuanlan.zhihu.com/p/403903892 https://blog.csdn.net/chentuo2000/article/details/119939573 一文中我们已经编译成功了海康威视SDK的控制台程序consoleDemo。 在《海康威视SDK控…

弹性盒模型----容器属性

布局的传统方案&#xff0c;基于盒装模型&#xff0c;依赖display属性 position属性 float属性。他对于那些特殊的布局非常不方便&#xff0c;比如&#xff0c;垂直居中就不容易实现。  2009年&#xff0c;W3C提出了一种新的方案—-Flex布局&#xff0c;可以简便、完整、响应…

JQuery的表单操作

获取值&#xff1a;文本框&#xff0c;文本区域&#xff1a;$("#txt").attr("value")&#xff1b;多选框checkbox&#xff1a;$("#checkbox_id").attr("value")&#xff1b;单选组radio&#xff1a; $("input[typeradio][check…